Static v/s Dynamic memory:
- Applications are used to store and process the information.
- We use variables to store the data.
- We allocate memory to variables in 2 ways
Note the following:
- It is impossible to allocate memory at compile time.
- Compiler check whether the program is syntactically correct or not.
- If the program follows syntax rules, then compiler converts the source code into machine code.
- Compiler is not responsible for allocating the memory.
- Memory allocation to variables only at runtime either it is Static or Dynamic
- Allocate Fixed size of memory is called Static Memory.
- Primitive variables have fixed memory.
Static Memory allocate to Arrays, Strings and Structures:
- Arrays and Strings are called Derived data types.
- Structures are called User defined data types.
- We allocate memory to these types in both the ways.
The following diagram represents static memory allocation:
- The memory block size can modify after allocation.
- We use pointer type variables to allocate dynamic memory.
- Pointer stores memory block address of any size.