+ 1

What if we want h=45 and l or w by default.??(see code below)

int volume(int l=1, int w=1, int h=1) { return l*w*h; } int main() { cout << volume() << endl; cout << volume(5) << endl;//l=5 & w/h by default cout << volume(2, 3) << endl; cout << volume(3, 7, 6) << endl; } /* Output 1 5 6 126 */

14th Jan 2017, 8:34 AM
Yashwant Kumar Sonkar
Yashwant Kumar Sonkar - avatar
2 Respostas
+ 2
You can set default values for arguments only from right so if you want to set L and W by default you must set H also as default or you can change the order of the arguments.
14th Jan 2017, 10:36 AM
Rishabh Agrawal
Rishabh Agrawal - avatar
+ 1
int volume (int h=1, int l=1, int w=1){ return l*w*h; } put the argument for which you don't want a default value first and the arguments which you by default to the end.
14th Jan 2017, 9:28 AM
Akash Middinti