General Discussions

malloc( ) in C

Function malloc() is used to dynamically allocate the memory in C. The general syntax goes the following way:

(type_casting) malloc (size)

let us understand it in detail in the form of a conversation:

malloc1

malloc2

That’s how the components of the syntax:
“(type casting the pointer) malloc(specifying the size) “
can be understood.

 

A sample source code can be seen below:

#include<stdio.h>
#include<stdlib.h>

int main()
{
    int * a;
    a = (int *) malloc(sizeof(int)*10);
    return 0;
}

One thought on “malloc( ) in C

Let me Know What you Think!