Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

a) Identify the following declarations. Ex. int i (integer variable) float a[l0](array of 10 real nos) int (*f())() void *f int (*f()) [] void *f int f[] [] [] char *(*f) () int (*f[]) [] float(*f) [] [] float **f int ******f

2153


I have seen function declarations that look like this

1040


How can I ensure that integer arithmetic doesnt overflow?

1161


Explain what is the difference between functions getch() and getche()?

1049


Which is not valid in C a) class aClass{public:int x;}; b) /* A comment */ c) char x=12;

1071


Which is an example of a structural homology?

1321


Why malloc is faster than calloc?

1062


Write a code to generate divisors of an integer?

1063


Why static variable is used in c?

1035


What is a struct c#?

1047


Difference between macros and inline functions? Can a function be forced as inline?

1267


What is atoi and atof in c?

1084


Should a function contain a return statement if it does not return a value?

1074


Write a program that accept anumber in words

1758


How can I rethow can I return a sequence of random numbers which dont repeat at all?

1188