I am trying to learn C, and I'm a bit suspended from pointers to pointers. I think I understand why you need this, but I can not make my head wrap around what is happening.
For example, the following code does not work, as I would expect this:
#include <stdio.h> int newp(char **p) { char d = 'b'; *p = &d; /*printf("**p = %c\n", **p);*/ return 1; } int main() { char c = 'a'; char *p = &c; int result; result = newp(&p); printf("result = %d\n", result); printf("*p = %c\n", *p); printf("c = %c\n", c); return 0; }
As a result, I get the following:
result = 1 *p = c = a
* p prints like nothing. Instead, I would expect *p = b .
However , if I uncomment line 6 ( printf in the newp function), I get the following:
**p = b result = 1 *p = b c = a
What am I missing?
source share