Pointers to pointers in C ++
A pointer to a cursor is an unidirected form or a string of pointers. Typically, a pointer contains the address of a variable.
A pointer to a cursor is an unidirected form or a string of pointers. Typically, 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 shown in the diagram below:
A variable, which is a pointer to a pointer, must be declared. This is done by placing an asterisk (*) in front of its name. For example, the following is a pointer to a pointer to an int:
int ** var ;
When a target value is pointed by a pointer to a pointer, accessing that value requires that the asterisk operator be applied twice, as in the example:
#include using namespace std ; int main () { int var ; int * ptr ; int ** pptr ; var = 125 ; // lay dia chi cua var ptr = & var ; // lay dia chi cua ptr boi su dung dia chi cua toan tu & pptr = & ptr ; // Lay gia tri boi su dung pptr cout << "Gia tri cua var la: " << var << endl ; cout << "Gia tri tai *ptr la: " << * ptr << endl ; cout << "Gia tri tai **pptr la: " << ** pptr << endl ; return 0 ; } Running the above C ++ program will produce the following results:
According to Tutorialspoint
Previous article: Array of pointers in C ++
Next lesson: Pass the cursor to the function in C ++
Discover more
operators in C ++Share by
David PacYou should read it
- Array of pointers in C ++
- How to Create Pointers in C
- Arithmetic pointer in C / C ++
- Cursor in C
- Cursor NULL in C / C ++
- The Quiet Details That Make a Sports Betting Platform Feel Reliable
- Instructions on creating toy set images with ChatGPT AI
- How are AI agents changing the journalism industry?
- Pass cursor to function in C ++
- Returns the pointer from the function in C ++
- C ++ exercises have solutions (sample code) for variables, data types, and operators