Default Value Passing in a Function in C++ - BunksAllowed

BunksAllowed is an effort to facilitate Self Learning process through the provision of quality tutorials.

Community

demo-image

Default Value Passing in a Function in C++

Share This

Remember that the default values should be passed to the function as last few parameters.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
using namespace std;
class Test {
public:
double getInterest(int principal, int year, double rate = 5.5) {
return principal * year * rate / 100;
}
};
int main() {
Test t;
cout << t.getInterest(1000, 2, 10) << endl;
cout << t.getInterest(1000, 2) << endl;
return 0;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX


Happy Exploring!

Comment Using!!

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.