Every variable lives at a memory address. A pointer is a variable that stores an address.
&x: the address of x.
int *p = &x;: p points to x.
*p: the value at that address (dereferencing). Changing *p changes x.
An array name acts as a pointer to its first element, so *(arr + 1) is arr[1].
💡 Key Takeaways: C Pointers
Mastering C Pointers helps you write clean and reliable C code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.
C Pointers Code Example
C
#include <stdio.h>
int main() {
int x = 10;
int *p = &x;
printf("x = %d\n", x);
printf("*p = %d\n", *p);
*p = 25;
printf("x after *p = 25: %d\n", x);
int arr[] = {5, 10, 15};
int *q = arr;
printf("Second element: %d\n", *(q + 1));
return 0;
}
Output
x = 10
*p = 10
x after *p = 25: 25
Second element: 10
Run this example on your own computer. The "Get Started" lesson shows how to set it up.