C++ tutorial-C++ function overloading

C++ function overloading

Overloaded functions are functions that have the same name but different number of parameters and/or data types.



using std::endl;

int Max(int val1, int val2){

            if(val1>val2) return val1;

            else return val2;


float Max(float val1, float val2, float val3){


                        if(val1>val3) return val1;

                        else return val3;}

            else if(val2>val3) return val2;

            else return val3;


void main(){

    cout<<"The maximum value among 12, 10, and 20 is:"<<Max(12,10,20)<<endl;

    cout<<"The maximum value among 12.5, 10.5, and 20.5 is:"<<Max(12.5,10.5,20.5)<<endl;



John comment


Much thanks for these C++ programming examples! I really appreciate them.

Troy comment


for more C++, C exercises,
please visit http://ccphplusplus.blogspot.com/


This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.