Crash Course in C Dynamic Allocation

ingolia@mit.edu

Dynamic Allocation

Crash Course in C

The function returns an untyped pointer to the

allocated memory, or NULL if the memory cannot

be allocated.

sz This argument specifies the size, in bytes, of

the memory to be allocated.

void *malloc(size_t sz);

The malloc function is used to allocate memory

malloc

Dynamic Allocation of Memory

|double| = 8

printf("|double| = %d\n", 8);

At compile time, a sizeof expression is expanded

into an integer.

int main(void)

{

printf("|double| = %d\n",

sizeof(double));

return 0;

}

Always use sizeof to determine the size of data.

sizeof

Dynamic Allocation of Memory

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download