Im a beginner level programmer in C and want to know how can I use malloc or calloc functions for dynamic memory allocation without typecasting...?
macrogeek
0
Newbie Poster
Recommended Answers
Jump to PostNo casting or typecasting is needed for malloc(). It returns a void pointer which the program will automatically change to the right type, for you. Very rarely, you'll need to do a cast of the pointer, manually.
You need to include stdlib.h for malloc to work.
If you …
Jump to PostWell, casting is not the same thing as typecasting. Typecasting just creates an "alias" (another name), your program can use, for a certain datatype (typically a struct name).
A cast in C is redundant, generally. It doesn't hurt to make them (if you're very careful to make it right), …
Jump to Post>Well, casting is not the same thing as typecasting.
Erm, yes it is.>Typecasting just creates an "alias" (another name), your program
…
>can use, for a certain datatype (typically a struct name).
You're thinking of typedefing. Casting, typecasting, explicit conversion, and type coercion are pretty much the same thing.
All 11 Replies
Adak
419
Nearly a Posting Virtuoso
prvnkmr449
-8
Junior Poster
macrogeek
0
Newbie Poster
Adak
419
Nearly a Posting Virtuoso
Narue
5,707
Bad Cop
Team Colleague
Adak
419
Nearly a Posting Virtuoso
Narue
5,707
Bad Cop
Team Colleague
Adak
419
Nearly a Posting Virtuoso
prvnkmr449
-8
Junior Poster
ronaldeddy
0
Newbie Poster
manojwali
-4
Light Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.