PAUSE
ENCORE5
ENCORE
BOX
ILLUSTRATION
GO
The function malloc() allocates the requested number of bytes in
the main memory, and returns the address of the allocated memory!
The malloc() syntax is:
char *malloc(size); unsigned size;
The above declaration says that the function returns
a pointer to a character string of size bytes.
malloc ( unsigned(15)); may allocate the area:
37256 37270
And return 37256 as the address of the allocated memory space!
If you wished to allocate the space for a variable of type other
than char, then you would employ the C cast, i.e., prepend
the malloc() expression with the type you want!
For example, if you wished to allocate space for a variable
of type bank_rec from the previous example, and return
the address to that area, then the expression would become:
(bank_rec *) malloc( sizeof(bank_rec));
Please note that the function sizeof()
returns the size of the object in bytes!