Skip to content
UPEEC

Parameters and Return Values

Parameters carry data into a function; the return value carries the result back out.

Beginner
Comments 0

Parameters are the names in the function definition; arguments are the actual values you pass when calling it.

int add(int a, int b) {   // a and b are parameters
    return a + b;
}
int sum = add(2, 3);      // 2 and 3 are arguments

A function can return one value (or nothing — void in C). To return several values, return a structure/tuple or write through pointers/references.

Most languages also support default values (def f(x, gain=1)) and named arguments.

Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.

Discussion (0)

Sign in or join free to ask questions and discuss this topic.