Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   malloc allocation (http://www.go4expert.com/forums/malloc-allocation-t26748/)

answerme 20Sep2011 22:50

malloc allocation
 
hi
when I do

ptr=(int*)malloc(10);
Does the memory allocate of 10 bytes are in continuous memory area .
Does malloc allocates memory conitinous

xpi0t0s 21Sep2011 03:29

Re: malloc allocation
 
Yes to both, although this is not good use of malloc. It allocates 10 bytes, but you should allocate N*sizeof(int) instead, where N is how many ints you want. If ints are 4 bytes on your system, this will allocate two and a half of them, of which only the first two are useful.

raixyz 24Oct2011 10:43

Re: malloc allocation
 
That is to say it returns a pointer of type void * that is the start in memory of the reserved portion of size number_of_bytes. If memory cannot be allocated a NULL pointer is returned.


All times are GMT +5.5. The time now is 10:40.