-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFunction.cpp
53 lines (44 loc) · 1.02 KB
/
Function.cpp
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <iostream>
using namespace std;
int sum (int a, int b) //function declaration (here int a and int b are parameters)
{
int c; //function defination/body
c = a+b;
return c;
}
// DEfault parameter example
// You can also use a default parameter value, by using the equals sign (=).
// If we call the function without an argument, it uses the default value ("Norway"):
void myFunction(string country = "Norway") {
cout << country << "\n";
}
// Pass By Reference
void swap(int &x, int &y)
{
int z = x;
x = y;
y = z;
}
// Function Overloading
// With function overloading, multiple functions can have the same name with different parameters:
int add(double a, double b)
{
return a+b;
}
void add(int a = 9)
{
cout<<a;
}
int main()
{
int x = 10;
int y = 20;
sum(x,y); //function call (here x, y are arguments)
swap(x,y);
cout<<x<<y<<"\n";
// cout<<plus(x)<<"\n";
double a = 2.5;
double b = 3.5;
cout<<add(a,b)<<"\n";
add();
}