Using default arguments to archive overloading in functions
In recent days, I began leaning C++. And this is my first work.
#include <iostream> #include <limits.h> using namespace std; int max(int, int, int c=sizeof(INT_MIN)); int main() { cout << "Enter 3 digits:" << endl; int a,b,c; cin >> a >> b >> c; cout << "The max of 3 digits is " << max(a,b,c) << endl; cout << "The bigger one of first 2 digits is " << max(a,b) << endl; return 0; } int max(int a, int b, int c) { if(b>a) a=b; if(c>a) a=c; return a; }
评论