C · Course navigation

C Pointers

Work with memory addresses.

On this page

The concept

A pointer holds an address. The & operator gets an address; * dereferences it. Only dereference a valid pointer.

Code example

C
#include <stdio.h>
int main(void) {
  int score = 91;
  int *pointer = &score;
  printf("%d\n", *pointer);
  return 0;
}
Output
91

Follow the code

Open the walkthrough to inspect the example one step at a time.

Show guided walkthrough
Guided walkthroughReady
1#include <stdio.h>
2int main(void) {
3 int score = 91;
4 int *pointer = &score;
5 printf("%d\n", *pointer);
6 return 0;
7}

Follow the example

Start to inspect the source, values, and output. These prepared steps explain the published sample; grouped loop steps describe multiple iterations.

View the complete dry-run table
Prepared trace of the published program. Some rows group repeated iterations.
Step / lineWhat happensState after stepOutput so far
Store 91 in score.score = 91
—
Store the address of score in pointer.pointer = &score
—
Dereference pointer to read score.pointer = &score
91

Behind the scenes

How C processes this code

The C compiler produces a native program. Variables occupy memory, and execution enters main.