15
How to use it pointer to pointer? I find it hard to tell what it is memory address and memory value when I try to use pointer to pointer, it seems mysterious to me. Someone could give me an explanation and an example of the use of pointer to pointer?
My attempt to implement pointer to pointer:
#include <stdio.h>
int main(void)
{
//Este código gera um erro. E não exibe o valor da variável "ponteiroDoPonteiro".
int *ponteiro, **ponteiroDoPonteiro, valor;
valor = 50;
ponteiro = &valor;
*ponteiroDoPonteiro = &ponteiro;
printf("\n%d", **ponteiroDoPonteiro);
return 0;
}
In
*ponteiroDoPonteiro = &ponteiro;
you shouldn’t use the*
- So you’re saying that the value ofint**
(i.e. aint*
) must be the address of aint*
(i.e. aint**
). I can’t give a full answer at the moment, but a reasonable approach is as follows: every time you put a&
in front the result type wins a*
every time you put a*
in front the result type gets a*
unless. :)– mgibsonbr
Thanks for the help.
– gato
Let’s say every memory cell in the computer corresponds to a house. These houses are all organized in a single street and each house has a number. This house number is the address. Inside each house, there is someone living, and this resident (which is also a number) is the stored value. In the case of a pointer to pointer, we have the number of some house, and when we look inside this house, we find a resident who is a number. The number this resident has represents the number of some other house that has some other resident.
– Victor Stafusa