Why a pointer * is inputted for expressions alonem | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
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); }

29th Jul 2020, 2:28 PM
Dev Anand
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.
29th Jul 2020, 2:44 PM
Slick
Slick - avatar