On Wed, May 6, 2009 at 11:11 AM, Ahmed Mahmoud <[email protected]> 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

Reply via email to