-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLecture30.cpp
More file actions
96 lines (63 loc) · 1.57 KB
/
Copy pathLecture30.cpp
File metadata and controls
96 lines (63 loc) · 1.57 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// macro
#include<iostream>
using namespace std;
#define PI 3.14
int main() {
int r = 5;
//double pi = 3.14;
double area = PI * r * r;
cout << "Area is " << area << endl;
return 0;
}
// inline function
#include<iostream>
using namespace std;
inline int getMax(int& a, int& b) {
return (a>b) ? a : b;
}
int main() {
int a = 1, b = 2;
int ans = 0;
ans = getMax(a,b);
cout << ans << endl;
a = a + 3;
b = b + 1;
ans = getMax(a,b);
cout << ans << endl;
return 0;
}
// global varuiable
#include<iostream>
using namespace std;
inline int getMax(int& a, int& b) {
return (a>b) ? a : b;
}
int main() {
int a = 1, b = 2;
int ans = 0;
ans = getMax(a,b);
cout << ans << endl;
a = a + 3;
b = b + 1;
ans = getMax(a,b);
cout << ans << endl;
return 0;
}
// default argument
#include<iostream>
using namespace std;
// the game of default agrument is laways starts from right most part of the function or code to left part
void print(int arr[], int n , int start = 0) {
for(int i = start; i<n; i++) {
cout << arr[i] << endl;
}
}
int main() {
int arr[5] = {1,4,7,8,9};
int size = 5;
print(arr, size);
cout << endl;
print(arr, size, 2);
return 0;
}
// constant variables pending