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;
}

Advertisements

Let me Know What you Think!

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s