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

What does a derived class inherit from a base class a) Only the Public members of the base class b) Only the Protected members of the base class c) Both the Public and the Protected members of the base class d) .c file

660


What is substring in c?

632


Is c programming hard?

572


What are the usage of pointer in c?

701


What does c mean in basketball?

559






A function can make the value of a variable available to another by a) declaring the variable as global variable b) Passing the variable as a parameter to the second function c) Either of the two methods in (A) and (B) d) binary stream

662


What does the function toupper() do?

647


Are pointers integers in c?

604


5 Write an Algorithm to find the maximum and minimum items in a set of ā€˜nā€™ element.

1576


which is conditional construct a) if statement b) switch statement c) while/for d) goto

732


How can I avoid the abort, retry, fail messages?

651


What is clrscr in c?

666


How can I find out if there are characters available for reading?

635


What is the difference between c and python?

577


What is 02d in c?

632