Pointer to Pointer Dynamic Allocation
A pointer to pointer, denoted as double pointer (**
).
This is a pointer that holds the memory address of another pointer. In simple words, it is a variable whose value is the address of another pointer. This concept might sound complex at first, but it provides a powerful mechanism for dealing with advanced dynamic memory allocation.
Syntax
main.cpp
- ptr1: is a pointer to an integer (
int*
); - ptr2: is a double pointer to an integer (
int**
).
Dynamic Allocation of a Two-Dimensional Array
If you want to create a two-dimensional array dynamically (at runtime) you have to use a pointer to a pointer for the rows.
And then initialize each row with dynamic array (like in previous chapter)
Tarefa
- Dynamically allocate a two dimensional array.
- Dynamically allocate the arrays as elements.
- Free all allocated memory.
Tudo estava claro?
Conteúdo do Curso
C++ Pointers and References
3. References Fundamentals
C++ Pointers and References
Pointer to Pointer Dynamic Allocation
A pointer to pointer, denoted as double pointer (**
).
This is a pointer that holds the memory address of another pointer. In simple words, it is a variable whose value is the address of another pointer. This concept might sound complex at first, but it provides a powerful mechanism for dealing with advanced dynamic memory allocation.
Syntax
main.cpp
- ptr1: is a pointer to an integer (
int*
); - ptr2: is a double pointer to an integer (
int**
).
Dynamic Allocation of a Two-Dimensional Array
If you want to create a two-dimensional array dynamically (at runtime) you have to use a pointer to a pointer for the rows.
And then initialize each row with dynamic array (like in previous chapter)
Tarefa
- Dynamically allocate a two dimensional array.
- Dynamically allocate the arrays as elements.
- Free all allocated memory.
Tudo estava claro?