Q:

What is static memory allocation and dynamic memory allocation?

0

What is static memory allocation and dynamic memory allocation?

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Answer:

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 external or internal linkage or declared with static storage-class. It’s initialized only once, prior to 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.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

What is the return value of malloc (0)?... >>
<< What is the purpose of realloc( )?...