Buet Admission Quest Basic
Buet Admission Quest Basic
malloc()
calloc()
free()
realloc()
While allocating memory on heap we need to delete the memory manually as memory is
not deallocated by the compiler itself even if the scope of allocated memory finishes (as
in case of stack).
Static Memory Allocation Dynamic Memory Allocation
Memory allocated during compile time is Memory allocation done at the time of
called static memory allocation. execution is known as dynamic memory
allocation.
It uses stack for managing the static It uses heap for managing the dynamic
allocation of memory. allocation of memory
It is less efficient It is more efficient
Faster execution than dynamic Slower execution than static
In static memory allocation, once the In dynamic memory allocation, when
memory is allocated, the memory size memory is allocated the memory size
cannot change. can be changed.
Example: Given an array, arr[4][3] with base value 2000 and the size of each
element is 2 Byte in memory. Find the address of arr[1][0] with the help of row-
major order and column major order?
Solution:
Solution:
Here:
Base address B = 100
Storage size of one element store in any array W = 1 Bytes
Row Subset of an element whose address to be found I = 8
Column Subset of an element whose address to be found J = 6
Lower Limit of row/start row index of matrix LR = 1
Lower Limit of column/start column index of matrix = 1
Number of column given in the matrix N = Upper Bound – Lower Bound + 1
= 15 – 1 + 1
= 15