+ 6
Pointer to pointer
What does it mean? any examples
5 Respostas
+ 10
A pointer which stores the address of another pointer.
int x = 5;
int* ptr = &x;
int** ptr2ptr = &ptr;
std::cout << *(*ptr2ptr);
+ 9
int** array = new int*[size];
declares a pointer of type int*, and allocates a specified size of int* to it. You now have an array of int pointers.
+ 4
can you explain me??please
int** array = new int*[size]
+ 1
include <iostream>
using namespace std;
int main () {
int var;
int *ptr;
int **pptr;
var = 3000;
// take the address of var
ptr = &var;
// take the address of ptr using address of operator &
pptr = &ptr;
// take the value using pptr
cout << "Value of var :" << var << endl;
cout << "Value available at *ptr :" << *ptr << endl;
cout << "Value available at **pptr :" << **pptr << endl;
return 0;
}
When the above code is compiled and executed, it produces the following result −
Value of var :3000
Value available at *ptr :3000
Value available at **pptr :3000
+ 1
A pointer to a pointer is a form of multiple indirection or a chain of pointers. Normally, a pointer contains the address of a variable. When we define a pointer to a pointer, the first pointer contains the address of the second pointer, which points to the location that contains the actual value.