Parameters & Arguments
The words "parameter" and "argument" are often used interchangeably in casual conversation, but they refer to two different things. Knowing the difference makes it much easier to read compiler messages and documentation precisely.
Parameters vs Arguments
Parameter — a variable listed in the function's definition (or declaration) that describes what kind of input the function expects.
Argument — the actual value you supply for a parameter at a specific call site.
Parameters vs arguments
#include <stdio.h>
// 'a' and 'b' are PARAMETERS: names + types describing expected input
int multiply(int a, int b) {
return a * b;
}
int main(void) {
int x = 6, y = 7;
// 6 and 7 (or x and y) are the ARGUMENTS: actual values supplied here
int result = multiply(x, y);
printf("%d\n", result);
return 0;
}Each call can pass different arguments, but the parameter names and types stay fixed by the function's definition.
Multiple Parameters
A function can take as many parameters as you need, separated by commas. Each one needs its own type, even if several parameters share the same type.
A function with several parameters
#include <stdio.h>
double average3(double a, double b, double c) {
return (a + b + c) / 3.0;
}
int main(void) {
printf("Average: %.2f\n", average3(4.0, 8.5, 6.0));
return 0;
}Everything in C Is Passed by Value
This is one of the most important facts about C functions: every argument is copied into its parameter when a function is called. The function works with its own local copy; the original value at the call site is never touched directly.
Modifying a parameter does not affect the caller
#include <stdio.h>
void increment(int n) {
n = n + 1; // only changes the local copy
}
int main(void) {
int x = 10;
increment(x);
printf("%d\n", x); // still prints 10
return 0;
}Prototypes Enable Type Checking
Because a prototype specifies the exact type of each parameter, the compiler can check every call site against it and catch mismatches before your program ever runs.
The compiler catches parameter mismatches
#include <stdio.h>
int square(int n); // prototype: expects exactly one int
int main(void) {
printf("%d\n", square(5)); // OK
printf("%d\n", square(5, 10)); // compiler error: too many arguments
printf("%d\n", square("five")); // compiler warning/error: wrong type
return 0;
}
int square(int n) {
return n * n;
}Term | Where it lives | Example |
|---|---|---|
Parameter | In the function's signature |
|
Argument | At the call site |
|