-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlec30_marcosglobal.cpp
103 lines (79 loc) · 1.25 KB
/
lec30_marcosglobal.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
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
97
98
99
100
101
102
103
// MACRO
/*
#include <iostream>
using namespace std;
#define PI 3.14 // MACRO
int main()
{
int r = 5;
// double pi =3.14;
double area = PI * r * r;
cout << " AREA IS :: " << area << endl;
return 0;
}
*/
// GLOBAL VARIABLE
/*
#include <iostream>
using namespace std;
int score = 15; // BAD PRACTICE
void a(int i)
{
cout << "Score << " << score << endl;
cout << ++i << endl;
}
void b()
{
cout << "Score << " << score << endl;
}
int main()
{
int i = 5;
a(5);
b();
{
int i = 2;
cout << i << endl;
}
cout << i << endl;
cout << "Score << " << score;
return 0;
}
*/
// INLINE FUNCS
/*
#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;
cout<<getmax(a,b)<<endl;
a = a + 3;
b = b + 1;
cout<<getmax(a,b)<<endl;
return 0;
}
*/
// DEFAULT ARGS
#include <iostream>
using namespace std;
void print(int arr[], int n,/*Default*/ int start = 0 /*args*/)
{
for (int i = start; i < n; i++)
{
cout << arr[i] << " ";
}
}
int main()
{
int arr[5] = {1, 4, 7, 8, 9};
int size = 5;
print(arr, size);
cout<<endl;
print(arr, size, 2);
}