Function Parameters and Arguments in C++
Parameters are variables defined in the function signature, while arguments are the actual values passed to the function when it is called.
Example: Function with Parameters
#include <iostream>
void displayAge(int age) {
std::cout << "Your age is: " << age << std::endl;
}
int main() {
displayAge(25);
return 0;
}
Explanation: The displayAge
function takes an integer parameter age
and prints it. 25
is passed as an argument when calling the function.
Key Takeaways
- Parameters are placeholders for values passed to the function.
- Arguments are the actual values provided during a function call.
- Parameters enhance function flexibility by allowing input values.