data-structures · beginner · ~15 min

Rectangle area

Pass a struct by value and use its fields.

Challenge

Define struct Rect { int w, h; }; and implement long rect_area(struct Rect r) returning w*h.

Starter code

struct Rect { int w, h; };

long rect_area(struct Rect r) {
    /* TODO */
    return 0;
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.