Q:

C++ program to demonstrate example of function overloading

0

C++ program to demonstrate example of function overloading

Function overloading is an important feature in C++, using function overloading – in a block/ scope we can declare multiple functions with same name. Function overloading can be done by using different type and number of arguments; it does not depend on return type of the function.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Function overloading example in C++.

/*C++ program to demonstrate example of function overloading.*/
#include  <iostream>
using namespace std;
 
void printChar();
void printChar( char c );
void printChar( char c, int num );
void printChar(int num, char c);
 
int main()
{
    printChar();
    printChar('#');
    printChar(10,'$');
    printChar('@',10);
     
    cout<< endl;
         
    return 0;
}
 
void printChar()
{
        cout<< endl<<"%";
}
void printChar( char c )
{
        cout<< endl<< c;
}
void printChar( char c, int num )
{
    int i=0;
         
    cout<< endl;
    for(i=0; i< num; i++)
        cout<< c;
}
void printChar(int num, char c)
{
    int i=0;
         
    cout<< endl;
    for(i=0; i< num; i++)
        cout<< c;
}

Output

    %
    #
    $$$$$$$$$$
    @@@@@@@@@@

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Most popular and Searched C++ solved programs with Explanation and Output

Similar questions


need a help?


find thousands of online teachers now
C++ program to read string using cin.getline()... >>
<< C++ program to demonstrate methods of passing argu...