ADVERTISEMENT
ADVERTISEMENT

Home » C++ programs » C++ basic programs

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.

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

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



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.