+ 1

functions default arguments

#include <iostream> using namespace std; int volume(int l=1, int w=1, int h=1) { return l*w*h; } int main() { cout << volume() << endl; cout << volume(5) << endl; cout << volume(2, 3) << endl; cout << volume(3, 7, 6) << endl; } help me understand this code like when we have volume(5) then how the formula works???

21st Jul 2019, 8:07 AM
Syed Shahrose
Syed Shahrose - avatar
1 Antwort
+ 2
i think: volume(5); is same as: volume(5, 1, 1); since in the line the function got declared the parameters have default values given (1).
21st Jul 2019, 8:26 AM
Anton Böhler
Anton Böhler - avatar