If a variable points to (a pointer to a pointer to a pointer to a pointer), What is the data type of this variable?
Well, I know you may be baffled when you see this title. Actually, this is a question that a freshman student asked me.
Well, do you know the type of this variable?
Here I want to share a story first. Once, I saw a group of kindergarten children playing. The children were having a competition about who could count to the bigger number.
In the beginning, one child said he could count to 500. Then the other jumped up and said he could count to 1000. The third child said he could count to 5000.
Afterward, they kept shouting:
“one hundred thousand”
Eventually, a child said he could count to infinity.
Young children who have just learned to count often have a sense of awe for larger numbers. For example, when I told my child that the result of subtracting one million from one million and one is one, she was very impressed with me.
Going back to our title, the question is simple.
- a pointer is a pointer
- the variable point to a pointer is a pointer
- the variable point to (a pointer to a pointer) is a pointer
- the variable point to (a pointer to a pointer to a pointer to a pointer) is still a pointer
No matter how nested it is, it is still a pointer. Just like whether it’s a hundred, a thousand, or a million, they are all numbers.
Some beginners continue to learn pointers after learning pointers, and they take it for granted that multi-level pointers are a very advanced thing. In fact, this is a wrong idea.
Some beginners, after learning about pointers, continue to study pointers to pointers, and they mistakenly think that multi-level pointers are something very advanced. However, this is a misconception.
I tell this student that, just as the complexity of mathematics is not reflected in the magnitude of numbers, the complexity of programming is not reflected in the nesting level of pointers.
Here is an example of a multi-level pointer: