#include<iostream>
using namespace std;
int main() {
struct Person
{
int m_id;
int m_age;
int m_height;
void display() {
cout << "m_id=" << m_id << endl;
cout << "m_age=" << m_age << endl;
cout << "m_height=" << m_height << endl;
};
};
Person person;
//person.m_id = 10;
//person.m_age = 20;
//person.m_height = 30;
//person.display();//观察结果
Person* p = &person;
p->m_id = 10;
p->m_age = 20;
p->m_height = 30;
p->display();//观察结果
//Person* p1 = (Person*)&person.m_age;
p1->m_id = 10;
//p1->m_id = 40;
//p1->m_age = 50;
//p1->display();//观察结果
person.display();、、观察结果
return 0;
}
#include<iostream>
using namespace std;
int main() {
struct Person
{
int m_id;
int m_age;
int m_height;
void display() {
cout << "m_id=" << m_id << endl;
cout << "m_age=" << m_age << endl;
cout << "m_height=" << m_height << endl;
};
};
Person person;
//person.m_id = 10;
//person.m_age = 20;
//person.m_height = 30;
//person.display();//观察结果
Person* p = &person;
p->m_id = 10;
p->m_age = 20;
p->m_height = 30;
p->display();//观察结果
//Person* p1 = (Person*)&person.m_age;
p1->m_id = 10;
//p1->m_id = 40;
//p1->m_age = 50;
//p1->display();//观察结果
person.display();、、观察结果
return 0;
}
转汇编可知为何结果不同