A Function is a collection of statements that are grouped together to perform an operation. A function in C++ is a block of code that, When the function is invoked from any part of the program, it all executes the codes defined in the body of the function. Function overloading is the ability to create multiple function with the same name, granted that they differ in either number or type of arguments. Compiler checks function signature for function overloading.
Function signature consists of three things :
The program demonstrates function overloading in C++, where multiple functions have the same name but different parameter lists.
#include<iostream> using namespace std; // Function Overloading int sum(int a,int b) { return a+b; } int sum(int a,int b,int c) { return a+b+c; } float sum(float a,float b) { return a+b; } int main() { cout<<"Total : "<<sum(10,20)<<endl; cout<<"Total : "<<sum(10,20,30)<<endl; cout<<"Total : "<<sum(10.25f,25.10f)<<endl; return 0; }
Total : 30 Total : 60 Total : 35.35To download raw file Click Here
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions