-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC++ Function Syntax Overloading.cpp
More file actions
78 lines (62 loc) · 1.67 KB
/
C++ Function Syntax Overloading.cpp
File metadata and controls
78 lines (62 loc) · 1.67 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/**
[PROGRAM] : C++ Function Overloading
[AUTHOR] : Saddam Arbaa
[Email] : <saddamarbaas@gmail.com>
With function overloading, multiple functions can have
the same name with different parameters:*/
#include <iostream>
using namespace std;
// function with 2 parameters
void print(char c, string cc)
{
cout << "char value is : " <<c << endl;
cout << "string value is : " << cc << endl;
}
// function with 2 parameters
void print(int num1, double num2)
{
cout << "Integer number is : " << num1 << endl;
cout << "double number is : " << num2 << endl;
}
// function with double type single parameter
void print(double num)
{
cout << "Double number is : " << num << endl;
}
// function with int type single parameter
void print(int num)
{
cout << "Integer number is : " << num << endl;
}
// function with char type single parameter
void print(char c)
{
cout << "char value is : " <<c << endl;
}
// function with string type single parameter
void print(string cc)
{
cout << "string value is : " << cc << endl;
}
// the main Function
int main()
{
// local variable declaration:
int x = 23;
double y = 12.3;
char c = 'a';
string cc = "yes";
// call function with 2 parameters
print(c, cc);
// call function with int type parameter
print(x);
// call function with double type parameter
print(y);
// call function with char type parameter
print('a');
// call function with string type parameter
print("thank for help");
// call function with 2 parameters
print(x, y);
return 0;// signal to operating system everything works fine
}/** End of main function */