C++ Function Definition default argument list on several parameters
#include <iostream> using namespace std; #include <iomanip.h> void de_fun(int i=5, long j=40034, float x=10.25,char ch='Z', double d=4.3234); // Prototype void main()/* ww w. ja v a 2 s . c o m*/ { de_fun(); // All defaults used. de_fun(2); // First default overridden. de_fun(2, 7); // First and second default overridden. de_fun(2, 7, 3.88); // First, second, and third de_fun(2, 7, 5.88, 'G'); // First, second, third, and fourth de_fun(2, 7, 5.88, 'G', .03); // No defaulting. return; } void de_fun(int i, long j, float x, char ch, double d) { cout << setprecision(4) << "i: " << i << " " << "j: " << j; cout << " x: " << x << " " << "ch: " << ch; cout << " d: " << d << "\n"; return; }