Struct Definition in C

Level 4147 keystrokes

Defines a struct with x and y coordinates, creates an instance, and modifies it.

C code

// Define a struct named Point with two integer members
1struct Point {
// x coordinate member
2 int x;
// y coordinate member
3 int y;
4};
5
// Create and initialize a Point instance
6struct Point p1 = {10, 20};
// Access struct members using dot notation
7printf("x: %d, y: %d\n", p1.x, p1.y);
// Modify the x member
8p1.x = 30;
// Print updated values
9printf("x: %d, y: %d\n", p1.x, p1.y);

Output

x: 10, y: 20
x: 30, y: 20
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.

  • ,× 7
  • ;× 7
  • .× 5
  • :× 4
  • "× 4
  • %× 4
  • (× 2
  • )× 2
  • {× 2
  • }× 2

More C examples at level 4

← C typing practice