-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctionoverloading.cpp
More file actions
36 lines (28 loc) · 1.07 KB
/
Copy pathfunctionoverloading.cpp
File metadata and controls
36 lines (28 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include<iostream>
using namespace std;
/*Function Overloading:
In C lang we cannot have more than one functions with the same name but in C++ , we can give same
name to different functions carrying out different sets of instruction. This is called function overloading.*/
int add(int x,int y){
int z;
z=x+y;
return z;
}//this function will add 2 integers
int add(int x,int y,int z){
int m;
m=x+y+z;
return m;
}//the function has same name but here it adds 3 integers and thats what special about this function
//Two functions with same name and parameters, but different return type are not considered oberloaded functions.
/*we can also make our task simple by adding using default arguments instead of function overloading.
For example: instead of writing this add(int x,int y) and int add(int x,int y,int z) .
we could have used int add(int x,int y,int z=0) thus intializing z as zero that can be later redefined */
int main()
{
int c,b;
c=add(5,7);
b=add(9,8,5);
cout<<"c="<<c<<endl;
cout<<"b="<<b<<endl;
return 0;
}