+ 1
When we need to point to another pointer in cpp ?
5 Respuestas
+ 2
You would use it if you want to reference an array of dynamically allocated arrays or objects.
Similar to as pointed out by AKC, a
double** array2D = new double[] { rowA, rowB, .. };
Can be used to access an array of pointer, each of these which points to an array of doubles.
Or you can have an array of objects
MyType** arrayOfObjs = new MyType[] { new MyType(), new MyType() };
(Be careful to delete these appropriately!)
However, when working with objects, it is more common to use a vector of dynamically allocated objects instead of a '**'.
+ 1
Use pointers-to-pointers like char** a so a stores a pointer to the memory where an adress (pointer) of a char is stored
+ 1
i mean what is the purpose
+ 1
pointer to a C array?
0
since c++ is mainly used for hardwares it deals with the limited amount of memory a hardware have. say for example you just created x=15, and the next line you add some value, this cause the program to make 2 memory allocation for the same variable,. if you use pointers it changes the value of x directly which means you will not create a duplicate variable in the memory thus saving more space in your hardwares' memory for further usage