malloc() how? what? 
Author Message
 malloc() how? what?

A(>I am new to C. I've come across malloc(). What is it? How do I use it?  Why
A(>do I use it?
A(>Please e-mail me if you know.
A(>Jeff Tcheou



 malloc() is used to dynamicly allocate memory.  malloc() uses pointer
variables. Here is an example of how to use malloc()

#include <stdlib.h>

char *string;


 string = (char *) malloc(81);


Basicly all this does is allocate enough memory to store 80 characters plus
the NULL char to end the string; If there was not enough free memory to
allocate the memory the function would have returned NULL.

Mark Jones
Virtual Link (334)807-0364

 * PowerAccess 1.06 To discover one knows nothing is the beginning of wisdom.

Sat, 10 Jan 1998 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. Malloc 2: The revenge of Malloc

2. malloc vs 'no-malloc' - help

3. C question : redefining a new malloc() calling standard malloc()

4. to malloc() or not to malloc(), that is the question

5. malloc crashes - malloc(256) returns 0(!) (_MT)

6. To malloc or not to malloc, that's the question!

7. memory to free or not to free, to malloc or not to malloc ?

8. To malloc (new) or not to malloc? When is the question.

9. malloc & free in c#

10. Override malloc,calloc,realloc and free?

11. std::bad_alloc ctor calls malloc????

12. Crash in Malloc


Powered by phpBB® Forum Software