5

For example, which term completes the sentence "p has 5 ____" in order to describe a situation like int *****p?

2
  • 6
    "Levels of indirection". (See en.wikipedia.org/wiki/…) Sep 18 at 10:11
  • Why do you need a specific term? If, for example, in some documentation, you write "p can be dereferenced 5 times" or "p can be dereferenced over 5 levels" does not make a huge difference in length or clarity".
    – Doc Brown
    Sep 18 at 18:49

1 Answer 1

4

Levels.

A pointer is used to point to a memory location of a variable. A pointer stores the address of a variable and the value of a variable can be accessed using dereferencing of the pointer. A pointer is generally initialized as:

datatype *variable name;

This above declaration is a single pointer but there can be more than this. This is called levels of pointers. According to ANSI C, each compiler must have at least 12 levels of pointers. This means we can use 12 * symbols with a variable name.

Level Of Pointers in C/C++:

Level of pointers or say chain can go up to N level depending upon the memory size. If you want to create a pointer of level-5, you need to precede the pointer variable name by 5 asterisks(*) at the time of declaration.

How many levels of pointers can we have in C/C++ - geeksforgeeks.org

See also

Just to be clear, this 12 thing they keep going on about is just counting how many *'s you can use in one go. But you can stick it in a loop and dereference as many times as you like. Well, so long as the value you find there never sends you outside of addressable memory.

3
  • Well 'level' alone is a shortcut and is not sufficient, and geeksforgeeks is not really autoritative. 'Level of indirection' would be more accurate and less ambiguous imho.
    – Christophe
    Sep 18 at 9:16
  • @Christophe adding “indirection” is as redundant as adding “dereference”. Also, I’m showing usage. I don’t recognize anyone as having authority here. It’s called what it’s called. That’s how language works. Sep 18 at 12:24
  • 1
    The term "level" isn't wrong, but to use it for the OPs case, one would still have to write "we can dereference this pointer over 5 levels". And for this, I don't see any benefits in comparison to "we can dereference this pointer 5 times". Saying "this pointer has 5 levels", however, is probably not clearly telling anyone what was meant.
    – Doc Brown
    Sep 18 at 18:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.