Structure Definition in C

Level 489 keystrokes

Defines a structure to represent a 2D point and accesses its members.

C code

// Define a structure named Point
1struct Point {
// Member for x coordinate
2 int x;
// Member for y coordinate
3 int y;
4};
5
// Create and initialize a Point variable
6struct Point p = {3, 5};
// Access members using dot notation
7printf("(%d, %d)\n", p.x, p.y);

Output

(3, 5)
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.

  • ;× 5
  • ,× 4
  • .× 2
  • "× 2
  • (× 2
  • )× 2
  • {× 2
  • }× 2
  • %× 2
  • \× 1

More C examples at level 4

← C typing practice