+ 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???
1 ответ
+ 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).