Structure Pointer in C

Level 4157 keystrokes

Uses arrow operator to access structure members through a pointer.

C code

// Define Rectangle structure
1struct Rectangle {
2 int width;
3 int height;
4};
5
// Create and initialize a Rectangle
6struct Rectangle rect = {10, 5};
// Create pointer to the structure
7struct Rectangle *ptr = ▭
// ptr->width is shorthand for (*ptr).width; 10 * 5 = 50
8printf("Area: %d\n", ptr->width * ptr->height);

Output

Area: 50
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
  • -× 2
  • ,× 2
  • "× 2
  • {× 2
  • }× 2
  • *× 2
  • =× 2
  • >× 2
  • :× 1

More C examples at level 4

← C typing practice