you are right ,but firstly you must read the question about the malloc from abcpqr70 he asked about the malloc function not the free and my answer to this question is exactly what he wants to know thanks
Eng A.Mahmoud --- On Wed, 5/6/09, Brett McCoy <[email protected]> wrote: From: Brett McCoy <[email protected]> Subject: Re: [c-prog] malloc To: [email protected] Date: Wednesday, May 6, 2009, 8:27 AM On Wed, May 6, 2009 at 11:11 AM, Ahmed Mahmoud <eng_hamada2585@ yahoo.com> wrote: > Malloc is a function used to allocate some space in the memory "allocate this > in the run time of the program" but you must assign this to a pointer to use > this and to free it > like" int*x=(int*) malloc(sizeof( int)); > the pointer x will be used to point to this and(int*) this will force the > space to store integer > and (sizeof(int) ) this means that the number of bytes you want to allocate > and thanks It's also important when talking about malloc() that the memory will persist even if the variable being used has gone out of scope. You must explicitly release the memory with free() before the variable goes out of scope so the memory is released (else you will have a memory leak in your program). Note also that in ANSI C an explicit cast to the pointer type is not required, but in C++ it is, but you should use 'new' and 'delete' in C++ if you can. -- Brett ------------ --------- --------- --------- --------- --------- - "In the rhythm of music a secret is hidden; If I were to divulge it, it would overturn the world." -- Jelaleddin Rumi [Non-text portions of this message have been removed]
