-
Notifications
You must be signed in to change notification settings - Fork 0
/
7.15-test.cpp
222 lines (208 loc) · 4.78 KB
/
7.15-test.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstring>
using namespace std;
struct antarctica_years_end
{
int year;
};
int main(void)
{
using namespace std;
antarctica_years_end s01, s02, s03;
s01.year = 1998;
antarctica_years_end* pa = &s02;
pa->year = 1999;
antarctica_years_end trio[3];
trio[0].year = 2003;
cout << trio->year << endl;
const antarctica_years_end* arp[3] = {&s01, &s02, &s03};
cout << arp[1]->year << endl;
const antarctica_years_end** ppa = arp;
auto ppb = arp;
cout << (*ppa)->year << endl;
cout << (*(ppb + 1))->year << endl;
return 0;
}
//using namespace std;
//char* getname(void);
//
//int main(void)
//{
// char* name;
//
// name = getname();
// cout << name << " at " << (int*)name << endl;
// delete[] name;
//
// name = getname();
// cout << name << " at " << (int*)name << endl;
// delete[]name;
//
// return 0;
//}
//
//char* getname()
//{
// char temp[80];
// cout << "Enter last name: ";
// cin >> temp;
// char* pn = new char[strlen(temp) + 1];
// strcpy(pn, temp);
//
// return pn;
//}
//指向结构体的指针
//struct inflatable
//{
// char name[20];
// float volume;
// double price;
//
//};
//
//int main(void)
//{
// using namespace std;
//
// inflatable* ps = new inflatable;
//
// cout << "Enter name of inflatable item: ";
// cin.get(ps->name, 20);
// cout << "Enter volume in cubic feet: ";
// cin >> (*ps).volume;
// cout << "Enter price: $";
// cin >> ps->price;
//
// cout << "Name: " << (*ps).name << endl;
// cout << "Volume: " << ps->volume << endl;
// cout << "Price: $" << ps->price << endl;
//
// delete ps;
//
// return 0;
//}
//int main(void)
//{
// using namespace std;
//
// char animal[20] = "bear";
// const char* bird = "wren";
// char* ps;
//
// cout << animal << " and ";
// cout << bird << "\n";
//
// cout << "Enter a kind of animal: ";
// cin >> animal;
//
// ps = animal;
// cout << ps << "!\n";
// cout << "Before using strcpy():\n";
// cout << animal << " at " << (int*)ps << endl;
// cout << ps << " at " << (int*)ps << endl;
//
// ps = new char[strlen(animal) + 1];
// strcpy(ps, animal);
// cout << "After using strcpy():\n";
// /*cout << ps << " at " << (int*)ps << endl;*/
// cout << animal << " at " << (int*)animal << endl;
// cout << ps << " at " << (int*)ps << endl;
//
// delete[] ps;
//
// return 0;
//}
//int main(void)
//{
// using namespace std;
//
// char flower[] = "rose";
// cout << flower << "s are red" << endl;
// int arr[] = { 0, 1, 2 };
// cout << arr << " is " << endl;
// cout << flower << endl;
// cout << arr << endl;
//
// return 0;
//}
//int main(void)
//{
// using namespace std;
//
// double wages[3] = { 10000.0, 20000.0, 30000.0 };
// short stacks[3] = {3, 2, 1};
//
// //两种获取数组地址的方式
// double* pw = wages;
// short* ps = &stacks[0];
//
// cout << "pw = " << pw << " , *pw = " << *pw << endl;
// pw = pw + 1;
// cout << "add 1 to the pw pointer:\n";
// cout << "pw = " << pw << " , *pw = " << *pw << endl;
//
// cout << "ps = " << ps << " , *ps = " << *ps << endl;
// ps = ps + 1;
// cout << "add 1 to the pw pointer:\n";
// cout << "ps = " << ps << " , *ps = " << *ps << "\n\n";
//
// //使用数组表示法访问两个元素
// cout << "access two elements with array notation\n";
// cout << "stacks[0] = " << stacks[0] << " , stacks[1] = " << stacks[1] << endl;
// //使用指针表示法访问两个元素
// cout << "access two elements with pointer notation\n";
// cout << "*stacks = " << *stacks << " , *(stacks + 1) = " << *(stacks + 1) << endl;
//
// cout << sizeof(wages) << " = size of wages array\n";
// cout << sizeof(pw) << " = size of pw pointer\n";
//
//
//
// return 0;
//}
//使用指针访问数组
//int main(void)
//{
// using namespace std;
//
// double* p3 = new double[3];
// p3[0] = 0.2;
// p3[1] = 0.5;
// p3[2] = 0.8;
//
// cout << "p3[1] is " << p3[1] << ".\n";
// p3 = p3 + 1;
// cout << "Now p3[0] is " << p3[0] << " and ";
// cout << "p3[1] is " << p3[1] << ".\n";
// p3 = p3 - 1;
// delete[] p3;
//
// return 0;
//}
//C++,new为指针开辟空间
//int main(void)
//{
// using namespace std;
//
// int nights = 1001;
// int* pt = new int;
// *pt = 1001;
//
// cout << "nights value = ";
// cout << nights << ": location " << &nights << endl;
// cout << "int ";
// cout << "value = " << *pt << ": location = " << pt << endl;
// double* pd = new double;
// *pd = 10000001.0;
//
// cout << "double ";
// cout << "value = " << *pd << ": location = " << pd << endl;
// cout << "location of pointer pd: " << &pd << endl;
// cout << "sizeof pt = " << sizeof(pt);
// cout << ": size of *pt = " << sizeof(*pt) << endl;
// cout << "size of pd = " << sizeof(pd);
// cout << ": size of *pd = " << sizeof(*pd) << endl;
//
// return 0;
//}