0
Where to use a function declared without variable?
int sum(int=5,int=6);
3 Answers
+ 7
int sum(int a = 5,int b = 6);
// or int sum(int = 5, int = 6);
int main() {
//...
int summation_1 = sum(); // calling sum(5, 6)
int summation_2 = sum(25); // calling sum(25, 6)
int summation_3 = sum(25, 35); // calling sum(25, 35)
//...
}
int sum(int a, int b) {
// some code
}
Edit:
int sum(int=5,int=6); <- This is valid
default parameters can be unnamed but IMHO having arbitrary placeholders (variables) keep the code appearance consistent.
+ 5
Thanks Swim, you are right. Unnamed default param is valid and there's no problem using that. But I always try to keep the declaration and definition signatures consistent . I think knowing all of which is necessary but at the end of the day it's a matter of preference.
0
Manjul wo ternary operator ma jo ratio: iska bad ata ha usr kaisa solve karta ha