Simvik

Build a struct

Fill in a struct's members and return it. An easy embedded C problem (Structs, enums and typedef), run and graded in the browser.

easy · Structs, enums and typedef · structs · typedef

point_t groups an x and a y coordinate into one type.

Return a point_t whose x is x and whose y is y.

Starter code

typedef struct {
  int x;
  int y;
} point_t;

point_t make_point(int x, int y) {
  point_t p = { 0, 0 };
  return p;
}

Example tests

Positive coordinates

point_t p = make_point(3, 4);
printf("%d %d\n", p.x, p.y);

Expected output:

3 4

Negative coordinates

point_t p = make_point(-2, -9);
printf("%d %d\n", p.x, p.y);

Expected output:

-2 -9

Learn it first

  • Structs, enums and typedef · Grouping values into structs, the dot and the arrow, naming choices with enum, and shorter names with typedef.

More Structs, enums and typedef problems