Functions with Multiple Parameters in C++
Functions in C++ can have multiple parameters, allowing for more complex and versatile operations.
Example: Function with Multiple Parameters
#include <iostream>
void displayInfo(std::string name, int age) {
std::cout << "Name: " << name << ", Age: " << age << std::endl;
}
int main() {
displayInfo("Rohini", 28);
return 0;
}
Explanation: The displayInfo
function takes two parameters: name
and age
. Both arguments are passed in the function call.
Key Takeaways
- Multiple parameters allow for more detailed function customization.
- Order of arguments must match the parameter list.
- Use commas to separate multiple parameters in the function call.