Parameters are variables listed in the function definition that act as input to the function.
They allow you to pass data into a function when you call it.
returnType functionName(type1 param1, type2 param2, ...) {
// function body
}
Example:
int add(int a, int b) {
return a + b;
}
Yahan a aur b parameters hain.
#include<iostream>
using namespace std;
void greet(string name) {
cout << "Hello, " << name << "!" << endl;
}
int main() {
greet("Nikhil");
greet("Ravi");
return 0;
}
Hello, Nikhil!
Hello, Ravi!
| Type | Description |
|---|---|
| Value Parameters | Actual value copied to function |
| Reference Parameters | Pass memory address, original variable affected |
| Default Parameters | Parameters with default values |