12.8 DYNAMIC MEMORY ALLOCATION

Q. What is static memory allocation?

A.In our programs, we declare variables. Consider the following declaration:

int a[10] ;

When the program gets compiled, the compiler reserves memory for an array of 10 integers. When the program starts running, this memory is assigned to variable a. The allocation is till the program ends. Hence, it is called static. (No change during program life time!)

This method is very natural and hence good. Does this type of allocation have any disadvantage? Yes. In programs, we use many variables. Hence, during execution of programs, a time comes after which we do not use a particular variable. However, memory is still allocated to it. Unfortunately, this memory cannot be utilized. It ...

Get Object Oriented Programming with C++, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.