Demonstrate missing and default arguments - C++ Function

C++ examples for Function:Function Parameter

Description

Demonstrate missing and default arguments

Demo Code

#include <iostream>
using namespace std;
void repchar(char='*', int=45);   //declaration with
//default arguments
int main()// w  w  w.j av  a  2 s.  c  om
{
   repchar();                     //prints 45 asterisks
   repchar('=');                  //prints 45 equal signs
   repchar('+', 30);              //prints 30 plus signs
   return 0;
}
// displays line of characters
void repchar(char ch, int n)      //defaults supplied
{
   for(int j=0; j<n; j++)
      cout << ch;
   cout << endl;
}

Result


Related Tutorials