Lesson 11 / 36

Parameters & Return Values

How data flows into and out of a function.

Parameters are local copies

When you call add(3, 4), the values 3 and 4 are copied into the parameters a and b. Changing a inside the function never affects the caller's variable.

Multiple return paths

A function can return from more than one place; execution stops at the first one reached.

int sign(int n) {
    if (n > 0) return 1;
    if (n < 0) return -1;
    return 0;
}

Only one value out

return sends back exactly one value. To get multiple results out, use pointers (parameters) or return a struct.