static and dynamic memory allocation in c language

Static memory allocation:

  • Explicitly allocating memory in the program source code by declaring variables, structures, and arrays is static memory allocation. Static memory allocation requires you to know when you’re writing the program exactly how much memory you need. The amount of memory allocated is specified at compile time.

Dynamic memory allocation:

  • The process of allocating memory at runtime is called dynamic memory allocation. Dynamic memory allocation allows the program to react, while it’s executing, to demands for memory, such as user input. The amount of memory allocated is specified at run time.

malloc()

  • A block of memory can be allocated using malloc. The malloc function reserves a block of memory of specified size and returns a pointer of type void. This means that we can assign it to any type of pointer.

void *malloc(int size);

 

null

Mr. Sandeep Soni

Founder, Trainer & CEO, Deccansoft Software Services.

Sandeep has 21 yrs of experience working in various Microsoft Technologies/Platforms incl. VB6.0, ASP, VC++, VB.NET, C#. He is involved in managing and architecting projects at Deccansoft. He will be your liaison to Deccansoft, for any kind of communication and project updates. He knows what works and what doesn’t, and what practices are most suitable for design and programming with the ultimate goal of producing a quality system.