Pointer Basics in C

Level 4137 keystrokes

Demonstrates pointer declaration, address-of operator, and dereferencing.

C code

// Declare an integer variable with value 42
1int value = 42;
// Declare pointer and assign address of value using & operator
2int *ptr = &value;
// Print the actual value stored in variable
3printf("Value: %d\n", value);
// %p expects a void*, so cast; the address differs on each run
4printf("Address: %p\n", (void *)ptr);
// Dereference the pointer with * to read the value at that address (42)
5printf("Via pointer: %d\n", *ptr);

Output

Value: 42
Address: 0x7ffd12345678
Via pointer: 42
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this C code and how often they appear.

  • "× 6
  • ;× 5
  • (× 4
  • )× 4
  • ,× 3
  • :× 3
  • *× 3
  • \× 3
  • %× 3
  • =× 2

More C examples at level 4

← C typing practice