Where to use a function declared without variable? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Where to use a function declared without variable?

int sum(int=5,int=6);

26th Jan 2018, 5:38 AM
manjul
manjul - avatar
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.
26th Jan 2018, 6:12 AM
Babak
Babak - avatar
+ 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.
28th Jan 2018, 9:25 AM
Babak
Babak - avatar
0
Manjul wo ternary operator ma jo ratio: iska bad ata ha usr kaisa solve karta ha
3rd Apr 2018, 5:37 PM
Deepak badhe
Deepak badhe - avatar