Computer Methods C Programming
Computer Methods C Programming
LECTURE 11
/* executable statements */
{
int innerInt; /* storage allocated for innerInt */
/* executable statements */
}
/* storage for InnerInt released */
/* more executable statements */
The casting in
y = (int *)malloc(n*sizeof(int));
is needed because malloc returns void * :
void * malloc(unsigned int nbytes);
The type (void *) specifies a generic pointer, which can be
cast to any pointer type.
The function realloc() changes the size of the object to which ptr points
and allocates size bytes which may be larger or smaller than the one
originally allocated.
The original contents of the space are preserved, being copied if necessary.