-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmuke_qihang.cpp
More file actions
113 lines (100 loc) · 1.9 KB
/
Copy pathmuke_qihang.cpp
File metadata and controls
113 lines (100 loc) · 1.9 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include<iostream>
using namespace std;
namespace my_workspace {
int min = 0;
int max = 0;
int func(bool __max,int a[],int count) {
int _min = a[0];
int _max = a[0];
for(int i = 0; i < count; i++) {
if(a[i] >= _max) {
_max = a[i];
}
if(a[i] <= _min) {
_min = a[i];
}
}
if(__max) {
return _max;
} else {
return _min;
}
return -1;
}
int getMax(int a,int b) {
cout << "int getmax" << endl;
if(a>b)
return a;
else
return b;
}
double getMax(double a,double b) {
cout << "float getmax" << endl;
if(a>b)
return a;
else
return b;
}
}
int func(int a,int b, int c=3) {
cout << a << "," << b << "," << c << endl;
}
int main() {
int a = 0;
int b = 0;
a = 2;
int const *p = &a; //same as const int *p = &a;
// *p = b; //error *p is readonly
int * const q = &a;
//q = &b; //error q is readonly
*q = b;
cout << a << endl;
const int * const k = &a;
a = b;
int *ptest = new int;
*ptest = 2;
cout << *ptest << endl;
delete ptest;
ptest = NULL;
int *mtest = new int[10];
mtest[5] = 6;
cout << *(mtest+5) << endl;
delete[] mtest;
mtest = NULL;
#if 0
int count;
cout << "Input count:" << endl;
cin >> count;
if( count <= 0 || count > 10) {
cout << "Invalid input!" << endl;
return -1;
}
int i = 0;
int a[count];
int loop = count;
while(loop > 0) {
int num = 0;
cin >> num;
a[i] = num;
if(i == 0) {
my_workspace::max = a[i];
my_workspace::min = a[i];
}
if(i>=2) {
if(a[i] > my_workspace::max)
my_workspace::max = a[i];
if(a[i] < my_workspace::min)
my_workspace::min = a[i];
}
i++;
loop--;
}
cout << "max:" << my_workspace::max << endl;
cout << "min:" << my_workspace::min << endl;
cout << "workspace max:" << my_workspace::func(1,a,count) << endl;
cout << "workspace min:" << my_workspace::func(0,a,count) << endl;
#endif
func(10,-1);
my_workspace::getMax(1,2);
my_workspace::getMax(1.0,2.0);
}