Demonstrates default argument list on several parameters. - C++ Function

C++ examples for Function:Function Parameter

Description

Demonstrates default argument list on several parameters.

Demo Code

#include <iostream>
using namespace std;
#include <iomanip>
void de_fun(int i=5, long j=40034, float x=10.25,char ch='Z', double d=4.3234); // Prototype
void main()/*from   w  w w  .ja  va  2s .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;
}

Result


Related Tutorials