Demonstrate variable arguments - C++ Function

C++ examples for Function:Function Parameter

Description

Demonstrate variable arguments

Demo Code

#include <iostream>
using namespace std;
void repchar(char, int);                  //function declaration
int main()/*from  www.  ja va  2s.c o  m*/
{
   char chin;
   int nin;
   cout << "Enter a character: ";
   cin >> chin;
   cout << "Enter number of times to repeat it: ";
   cin >> nin;
   repchar(chin, nin);
   return 0;
}
// function definition
void repchar(char ch, int n)
{
   for(int j=0; j<n; j++)
      cout << ch;
   cout << endl;
}

Result


Related Tutorials