C Pointers

Variables that store memory addresses.

✍️ 2 exercises in this lesson

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.

C Pointers Practice Exercises

Check what you learned in “C Pointers”.

/ 2 solved
Fill in the blank

Store the address of x in the pointer p.

int *p = x;
✓ Correct! Not quite. Try again.
Multiple choice

What does *p give you?

✓ Correct! Not quite. Try again.
to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.

Stuck on something?

Ask the community in the CodesInTech forum.

Need a developer?

Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.

Explore Our Services