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. 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:

Pointers to pointers in C ++ Picture 1

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:

Pointers to pointers in C ++ Picture 2

According to Tutorialspoint

Previous article: Array of pointers in C ++

Next lesson: Pass the cursor to the function in C ++

5 ★ | 1 Vote

May be interested

  • Array (Array) in C / C ++Array (Array) in C / C ++
    c / c ++ programming language provides data structures called arrays, stored in a set of data of the same type with fixed length. an array is used to store data sets, but it is useful if you think of an array of variables with the same type.
  • Cursor in CCursor in C
    pointer in the c language is easy to learn. some tasks in c language are made easier by pointers, and other tasks become more flexible, such as in memory allocation, which cannot be performed without using a cursor.
  • Apply immediately how to create beautiful effects for computer mouse pointersApply immediately how to create beautiful effects for computer mouse pointers
    come to tipsmake's article to learn how to create beautiful effects for your computer mouse pointer in the simplest way.
  • Reference in C ++Reference in C ++
    a reference variable is an alias, which is another name for an existing variable. when a reference is initialized with a variable, then either the variable name or the reference name can be used to reference that variable.
  • Read / write File in C ++Read / write File in C ++
    so far, we have used the iostream standard library, provided cin and cout methods to read from standard input and write to the corresponding standard output.
  • Cursor NULL in C / C ++Cursor NULL in C / C ++
    it is always a good practice to assign a null pointer to a pointer variable in case you don't know the exact address to be assigned. this is done at the time of variable declaration. a pointer that is assigned null is called a null pointer.
  • Replace the mouse cursor with funny picturesReplace the mouse cursor with funny pictures
    instead of the default windows mouse cursor, you can create more funny and lovely mouse pointers that suit your taste and help create more interest in working with computers.
  • How to restore the default theme in Windows 10How to restore the default theme in Windows 10
    in windows, you can use themes to 'personalize your computer. theme changes screen wallpapers, colors, sounds, screensavers and pointers on your computer at the same time and you can change the theme as often as you want. the following article will show you how to restore the default windows 10 theme.
  • How to keep the default desktop icons and mouse pointer when changing the Windows 11 themeHow to keep the default desktop icons and mouse pointer when changing the Windows 11 theme
    some themes that change the appearance of the screen can also change the desktop icons and even the mouse pointer. but what if you like the native windows icons or don't like the themed icons or mouse pointers?
  • Can Pokemon Go be played on a computer? The answer is yes!Can Pokemon Go be played on a computer?  The answer is yes!
    by software emulation and additional software to support positioning, we can completely play pokemon go right on the computer, comfortable catching pokemon without worrying about running out of battery when playing as on the phone.