Google News
logo
Embedded C - Interview Questions
What is static memory allocation and dynamic memory allocation?
According to C standard, there are four storage duration, static, thread (C11), automatic, and allocated. The storage duration determines the lifetime of the object.
 
The static memory allocation :
Static Allocation means, an object has an external or internal linkage or declared with static storage-class. It’s initialized only once, before program startup and its lifetime is throughout the execution of the program. A global and static variable is an example of static memory allocation.
 
The dynamic memory allocation :
In C language, there are a lot of library functions (malloc, calloc, or realloc,..) which are used to allocate memory dynamically. One of the problems with dynamically allocated memory is that it is not destroyed by the compiler itself that means it is the responsibility of the user to deallocate the allocated memory.
 
When we allocate the memory using the memory management function, they return a pointer to the allocated memory block and the returned pointer is pointing to the beginning address of the memory block. If there is no space available, these functions return a null pointer.
Advertisement