basics · beginner · ~15 min

Add two integers

Write and return from your first C function.

Challenge

Write your first C function: take two integers and return their sum.

Task

Implement int add(int a, int b) that returns a + b. No main — the grader calls your function.

Input

Two ints a and b.

Output

Returns their sum, as an int.

Example

add(2, 3)    ->   5
add(-4, 1)   ->   -3
add(0, 0)    ->   0

Edge cases

  • Negative operands work the same way.

Input format

Two ints a and b.

Output format

Their sum, as an int.

Starter code

int add(int a, int b) {
    /* TODO */
    return 0;
}

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