Simvik

Declare before use

Fix code that calls functions the compiler has not seen yet. An easy embedded C problem (Functions), run and graded in the browser.

easy · Functions · prototypes · debugging

The compiler reads a file from top to bottom. A function must be declared before the line that calls it.

This code does not compile. Fix it so that triple_plus_one(x) returns three times x, plus one. Keep all three functions.

Starter code

int triple_plus_one(int x) {
  return add_one(triple(x));
}

int triple(int x) {
  return x * 3;
}

int add_one(int x) {
  return x + 1;
}

Example tests

Two

printf("%d\n", triple_plus_one(2));

Expected output:

7

Zero

printf("%d\n", triple_plus_one(0));

Expected output:

1

Learn it first

  • Functions · Splitting a program into named pieces, passing values in and getting results back.

More Functions problems