1. Intro
Parameters and arguments are related but distinct terms. Parameters are the named variables listed in a function's signature (its declaration/definition) that describe what inputs the function expects. Arguments are the actual values you pass in when you call the function. By default, C++ passes arguments to functions using pass-by-value, meaning the function receives a copy of the data, not the original.
Cricket analogy: A net session drill plan lists 'batsman, bowler, pitch type' as slots to fill (parameters), while today's actual players like Kohli and Bumrah filling those slots are the arguments; the coach's notes on Kohli don't change the real Kohli.
2. Syntax
// 'a' and 'b' are PARAMETERS
int add(int a, int b) {
return a + b;
}
int main() {
int x = 10, y = 20;
int sum = add(x, y); // x and y are ARGUMENTS
return 0;
}3. Explanation
Think of parameters as placeholders in the function's blueprint, and arguments as the real values plugged into those placeholders at the call site. C++'s default pass-by-value mechanism means that when you call add(x, y), the function add receives its own independent copies of x and y inside its parameters a and b. Any changes made to a or b inside the function body affect only the copy — x and y in main() remain completely unchanged. This is the single most important fact to understand about ordinary C++ parameters: modifying a parameter inside a function does NOT affect the caller's original variable, unless you explicitly use references (&) or pointers (*) to allow the function to modify the original.
Cricket analogy: When a substitute fielder is handed a photocopy of the field placement chart to mark up during the over, scribbling on it never changes the captain's master chart — exactly like a copied parameter never altering the caller's original variable.
Pass-by-value copy gotcha: because arguments are copied by default, a function like void increment(int n) { n = n + 1; } will NOT change the caller's variable at all. To modify the original, you must pass by reference, e.g. void increment(int &n).
4. Example
#include <iostream>
using namespace std;
void modifyValue(int num) { // 'num' is a parameter, receives a COPY
num = num + 100;
cout << "Inside function, num = " << num << endl;
}
int main() {
int original = 5;
modifyValue(original); // 'original' is the argument passed
cout << "Outside function, original = " << original << endl;
return 0;
}5. Output
Inside function, num = 105
Outside function, original = 56. Key Takeaways
- Parameters are variables named in the function's signature; arguments are the actual values passed at the call site.
- By default, C++ uses pass-by-value: the function receives a copy of each argument.
- Changing a parameter inside a function does not affect the caller's original variable.
- Use reference parameters (&) or pointers to let a function modify the caller's original variable.
Practice what you learned
1. What are the named variables listed in a function's signature called?
2. What does C++ use by default when passing arguments to a function?
3. Given `void f(int n) { n = 50; }` and `int x = 5; f(x);`, what is the value of x after the call?
4. How can a function modify the caller's original variable directly?
5. In the call `add(x, y)`, what are x and y called?
Was this page helpful?
You May Also Like
Functions in C++
Learn what a function is in C++, why programs are broken into functions, and how reusability, modularity, and readability improve with them.
return Statement in C++
Understand how the return statement ends a function and optionally sends a value back to the caller, including void functions.
Default Arguments in C++
Learn how to give function parameters default fallback values in C++ and the rule that default arguments must be trailing parameters.
Related Reading
Related Study Notes in Programming
Browse all study notesApache Spark Study Notes
Programming · 30 topics
ProgrammingApache Flink Study Notes
Programming · 30 topics
ProgrammingHadoop Study Notes
Programming · 30 topics
ProgrammingSnowflake Study Notes
Programming · 30 topics
ProgrammingApache Airflow Study Notes
Programming · 30 topics
Programmingdbt (Data Build Tool) Study Notes
Programming · 30 topics