Can a pointer to a pointer to a pointer?

If C has pointers (char * names []) and pointers to pointers (char ** cur_name = names); Can a pointer to a pointer to a pointer?

Or a pointer to a pointer to a pointer is just a linked list? This may be a stupid question, but I would like to know the answer.

+5
source share
6 answers

Yes, you can have any number of pointer levels.

int x = 5; int *a = &x; int **b = &a; int ***c = &b; printf("%d %d %d %d\n", x, *a, **b, ***c); 

A pointer to a pointer to a pointer is not a linked list. A linked list is a structure type that contains a pointer to its own type:

 struct list { int data; struct list *next; }; 

So you can link them together in a list:

 struct list three = { 3, NULL }; struct list two = { 2, &three }; struct list one = { 1, &two }; struct list head = { 0, &one }; 

And iterating over them:

 for (struct list *node = &head; node->next; node = node->next) { printf("%d\n", node->data); } 
+5
source

Simply put,

Declare a variable - it doesn't matter what type - and represents a location in memory.

 int foo=1; 

Then you can declare another variable pointing to this variable.

 int *bar; bar = &foo; 

Expand it again - declare a pointer to this variable ... etc.

 int *baz; baz = &bar; 

A point has no limits for indirection levels to which any given pointer can be used or declared. And, syntactically, you can do

 int ****nthLevelPointer; 

Now, keeping track of this in code in a way that another person might need is another problem :)

+3
source

A simple example:

 struct List { struct List* next ; } struct List a ; struct List* p = &a ; p->next = p ; p = p->next ; p = p->next->next ; p = p->next->next->next ; p = p->next->next->next->next ; p = p->next->next->next->next->next ; p = p->next->next->, ... ,next->next->next ; 

shows that there is no theoretical limit for the depth of the pointer pointer.

+3
source

Your answer: yes. pointers are just references to memory.so, if we can refer to memory, we can refer to a pointer as well. You can get their size in a bunch of your process. You can also define them by a local variable. Use this scheme:

pointer a -----> pointer b -----> pointer c ------> (local variable or variable definition on the heap)

+1
source

Short answer: Pointers point to addresses in memory that may themselves contain more pointers. The limit is the number of addresses available.

A shorter answer: Yes, there may be pointer-pointer-pointer.

0
source

You can point to a pointer to a pointer to a pointer.

if you declare a variable like this:

 int ***ptr; 

then

 -> ptr will be a pointer to a pointer to a pointer to an int variable -> *ptr will be a pointer to a pointer to an int variable -> **ptr will be a pointer to an int variable -> ***ptr will be a int variable 

so:

 highest pointer level: ptr ... *ptr ... **ptr int variable ***ptr 
0
source

Source: https://habr.com/ru/post/1209377/


All Articles