3
I have a doubt about this : **ptr
I can understand everyone else (ptr++, &ptr, *ptr)
I don’t know the best way to understand how it works **ptr
(Pointed.)
Thanks to those who can clarify me is doubt .
3
I have a doubt about this : **ptr
I can understand everyone else (ptr++, &ptr, *ptr)
I don’t know the best way to understand how it works **ptr
(Pointed.)
Thanks to those who can clarify me is doubt .
4
The important part to understand this is understanding how pointers work.
Let’s imagine that we declare a pointer with the ABC content: const char *c = "ABC";
So, "ABC" is somewhere in the memory and the pointer is also in the memory. If we want to create a pointer to c, it’s also possible with the code:
const char **cp = &c;
In this case the cp pointer is also allocated in memory and is pointing to where the c pointer is.
For example, if we are looking at a chunk of memory:
Endereço
21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30
-----------------------------------------------
A | B | C | | 21 | | 25 | | |
Conteúdo
cp está no endereço 27 e aponta para o endereço 25.
c está no endereço 25 e aponta para o endereço 21.
no endereço 21, temos a string ABC.
3
Imagine you have several text pointers
char *lang_pt[] = {"rato", "teclado", "monitor"};
char *lang_en[] = {"mouse", "keyboard", "screen"};
and you want to make a single pointer that points to the language the user has chosen
char **lang_user;
if (rand() % 2) lang_user = lang_pt;
else lang_user = lang_en;
printf("2. %s\n", lang_user[1]); // teclado???? keyboard???
2
Quoting the Stack Overflow (in English):
And so on and so on...
https://stackoverflow.com/questions/5580761/why-use-double-pointer-or-why-use-pointers-to-pointers
Browser other questions tagged c
You are not signed in. Login or sign up in order to post.
+1, but lacked a
*
in his monologue.– tayllan