In This Repo, we will discuss different topics about memory management in c++ like how the computer deals with executable programs and how it stores its data in memory, dealing with pointers and reference and heap, call stack
- pointers and reference
- stack and heap
- how to avoid memory leak
- 1d,2d array under the hood
- advanced tips and tricks
example
/*
TODO : int arr[2][3] = {{1, 2, 3}, {4, 5, 6}};
* - arr in last example:
- is the pointer to the 2d array = arr
- is pointer to first node(array) in 2d array = *arr = arr[0] = &arr[0]
- is address to first element in first array = &arr[0][0]
? arr = *arr = arr[0] = &arr[0] = &arr[0][0]
* - arr+1 in last example:
- is pointer to second node(array) in 2d array = arr+1 = arr[1] = &ptr1[1]
- is address to first element in first array = &arr[1][0]= *(arr+1)
? arr+1 = arr[1] = &arr[1] = &arr[1][0] = *(arr+1)
* - (**arr) in last example:
- is the value of the first element in first array = **arr = arr[0][0]
? **arr = arr[0][0] = *arr[0] = *(*arr+0)
* - *(*arr+1) in last example:
- is the value of the second element in first array = *(*arr+1) = arr[0][1]
? *(*arr+1) = arr[0][1]
* - **(arr+1) in last example:
- is the value of the first element in second array = **(arr+1) = arr[1][0]
? **(arr+1) = arr[1][0] = *arr[1]
* - *(arr+1)+2 in last example:
- is address of last element in second array = *(arr + 1) + 2 = &arr[1][2]
? *(arr + 1) + 2 = &arr[1][2]
! notice that:
- when increase arr + 1 this jump to second node(array) in the 2d array
- when increase *arr + 1 this jump to second element in the 1d array
*/