0
Why a pointer * is inputted for expressions alonem
#include <stdio.h> int main() { int x = 5; int y; int *p = NULL; p = &x; y = *p + 2; /* y is assigned 7 */ y += *p; /* y is assigned 12 */ *p = y; /* x is assigned 12 */ (*p)++; /* x is incremented to 13 */ printf("p is pointing to the value %d\n", *p); }
1 Resposta
0
What this lesson showed me is that pointers can refer to variables or just values themselves.
int *p=NULL; //is just how you set up a blank interger pointer named p.
p=&x; // assigns the pointer to the address of x (so if x changes, so does p)
but,
*p=y; //is just saying that x (*p is assigned to the address of x) is equal to the current value of y wich was 12.
(*p, otherwise known as x, now equals 12)
So it looks like p would be the address of x and *p would be the x addresse's value.