+ 1

When we need to point to another pointer in cpp ?

12th Jan 2017, 7:20 PM
mojtaba noghabaee
mojtaba noghabaee - avatar
5 ответов
+ 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 '**'.
12th Jan 2017, 11:08 PM
Nathan
Nathan - avatar
+ 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
12th Jan 2017, 7:57 PM
Andreas K
Andreas K - avatar
+ 1
i mean what is the purpose
12th Jan 2017, 8:54 PM
mojtaba noghabaee
mojtaba noghabaee - avatar
+ 1
pointer to a C array?
12th Jan 2017, 9:18 PM
Andreas K
Andreas K - avatar
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
26th Jan 2017, 2:13 AM
Mark L. M.
Mark L. M. - avatar