C/C++ Arena

A pointer holds an address

&age is the address of age. Storing it in p makes p point at age, drawn as an arrow.

*p = 31; means "go to where p points and store 31 there", so age changes even though the line never mentions age.

#include <stdio.h>

int main(void) {
    int age = 30;
    int *p = &age;
    *p = 31;
    printf("age = %d\n", age);
    return 0;
}

Output:

age = 31

From the lesson: Pointers