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

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.


#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; }


Happy Exploring!

No comments:

Post a Comment

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