-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPractice.cpp
More file actions
43 lines (33 loc) · 832 Bytes
/
Practice.cpp
File metadata and controls
43 lines (33 loc) · 832 Bytes
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
#include <iostream>
#include <string>
using namespace std;
struct Vector {
float x, y, z;
};
struct Player {
string name;
int hp;
Vector position;
};
int main() {
Vector v;
v.x = 20, v.y = 30, v.z = 40;
cout << "A 3-space vector at " << v.x << ", " << v.y << ", " << v.z << endl;
Player me;
me.name = "William";
me.hp = 100;
me.position.x = me.position.y = me.position.z = 0;
cout << "me.position.x: " << me.position.x << endl;
//如下,多个指针可以同时指向一个变量,然后修改原变量的值。
Player* ptrMe;
ptrMe = &me;
ptrMe->hp -= 33;
ptrMe->name = "John";
cout << "ptrMe.hp: " << me.hp << ", " << "ptrMe.name: " << me.name << endl;
Player* ptr2Me;
ptr2Me = &me;
ptr2Me->hp -= 33;
ptrMe->hp += 100;
cout << "ptr2Me.hp: " << me.hp << ", " << "ptr2Me.name: " << me.name << endl;
system("pause");
};