pointer_variable=(typecasting
datatype*)malloc(sizeof(datatype));
This is the syntax for malloc?Please explain this,how it
work with an example?

Answer Posted / pramod

I'll add few more lines to answer above just to make it a
bit more understandable.


Malloc allocates consequetive blocks of memory of requested
size.Then it returns the starting address of this block ,
the address returned is of type void , since it is a void
pointer so we need to typecast it to one that we requested
so typecasting is done( This headache has been removed in
C++ by using new as new automatically does this typecasting)

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How do you construct an increment statement or decrement statement in C?

737


What is the method to save data in stack data structure type?

600


What is string function in c?

533


Explain how do you search data in a data file using random access method?

692


What is the difference between struct and typedef struct in c?

652






How will you print TATA alone from TATA POWER using string copy and concate commands in C?

916


explain what is a newline escape sequence?

683


what is recursion in C

607


how to write optimum code to divide a 50 digit number with a 25 digit number??

2748


Explain what is the advantage of a random access file?

659


What is the use of header files?

599


What are the advantages of the functions?

602


which is an algorithm for sorting in a growing Lexicographic order

1394


What are the different types of errors?

637


Is it possible to execute code even after the program exits the main() function?

808