Dear Neha,
Kindly refer to Dennis Ritchie's C Programming book. There you would get 
your querries replied. Moreover its a very important book for all C 
programmers - Novices to the Experts.
To hint you a bit towards your doubt....let me explain you like this,
the function ' malloc() ' isnt used not only for a a single data type. 
Rather 'malloc()' is the most frequent memory allocation function, used for 
structures to int and further the character strings as well. As such to give 
it a generic return type that matches all sorts of data type through 
typecasting, the function ' malloc() ' has a return type of ' void * '.
This is not a programmer's reply, but just give you a good explaination.
Hope you do the rest yourself........
Debasish






<html><DIV>
<P><FONT face="Lucida Handwriting, Cursive" color=#ff9900 
size=2>Karmennavava Dhikaraste, Maaphaleshu 
Kadaachanah</FONT></P></DIV></html>



----Original Message Follows----
From: neha lodha <[EMAIL PROTECTED]>
Reply-To: [email protected]
To: [email protected]
Subject: Re: [c-prog] Please help me to implement malloc function
Date: Fri, 12 Jan 2007 05:22:35 -0800 (PST)

i am casting return type coz this function will return the address of the 
int value that is to be stored at the dynamically alloted place!!

Paul Herring <[EMAIL PROTECTED]> wrote:          On 1/11/07, neha lodha 
<[EMAIL PROTECTED]> wrote:        The function malloc() is used to 
allocate memory at run time i.e for dynamic memory allocation.its general 
form is:
   void  *malloc(size);
   in malloc we don't specify the type of variables for which memory is 
required.rather we compute the memory considering its type and member of 
variables.so to allocate memory to 5 integer variables,we write:
   int *p;
   p=(int *)malloc(size of(int)*5);


Why are you casting the return from malloc()?






--
PJH

#713059 +(1255)- [X]

<SaintAlvus> Does the name Doctor Pavlov ring a bell?




---------------------------------
Bored stiff? Loosen up...
Download and play hundreds of games for free on Yahoo! Games.

_________________________________________________________________
Movie reviews, previews, news and gossips all here! 
http://content.msn.co.in/Entertainment/Default

Reply via email to