0

about pointers in C++ why we use ** in pointer to pointer

I just want to know the reason why we use ** in pointer to pointer

what is the main reason of using double indirections ?what is the logic behind it? or it is just a syntax?

are there any advantages or disadvantages

  • 3
    Sometimes you want to use a pointer to something. Sometimes the something is an int. So you have a pointer to an int. Sometimes the something is a pointer. So you have a pointer to a pointer. I don't understand why you are confused. – user253751 Feb 07 '23 at 13:57
  • 1
    If you have multiple levels of pointers how else would you represent that other than with `**`? Or are you asking why use multiple levels of pointers in the first place? In modern c++ there aren't many good reasons to do so (see https://wiki.c2.com/?ThreeStarProgrammer) – Alan Birtles Feb 07 '23 at 13:57
  • suppose you write the home address of your friend on a piece of paper. YOu place this piece of paper in your drawer X. Because you have so many drawers you take a piece of paper and write an X on it and put it in your pocket. Now you can always look in your pocket to find where to find the address of your friend. – 463035818_is_not_an_ai Feb 07 '23 at 14:06

0 Answers0