AnyCompiler

Pointers

A pointer is a variable that holds a memory address. &x gives you the address of x; int *p declares p as a pointer to an int; *p dereferences p, reading (or writing) the value it points to.

#include <stdio.h>

int main() {
    int x = 42;
    int *p = &x;
    printf("%d\n", *p);
    *p = 100;
    printf("%d\n", x);
    return 0;
}
Output
42
100

*p = 100 didn't change p itself — it changed x, the variable p points to. This is the mechanism every other language on this site hides behind references, borrowing, or object handles: C gives it to you directly, with no restrictions on when or how you use it.

Next: pointers and arrays — how array indexing and pointer arithmetic are secretly the same operation.

Practice exercise

Declare a variable x set to 10. Declare a pointer p to x, use it to set x to 99 through the pointer, then print x.