#include <iostream>
#include <stdio.h>
using namespace std;
int d_ = 1;
int s_ =2;
class A{
};
int main()
{
A *d = new A();
A *s = new A();
cout<<&d<<” “<<&s<<endl;
int i = 0;
int j = 1;
cout<<&i<<” “<<&j<<endl;
cout<<&d_<<” “<<&s_<<endl;
return 0;
}
#include <stdio.h>
using namespace std;
int d_ = 1;
int s_ =2;
class A{
};
int main()
{
A *d = new A();
A *s = new A();
cout<<&d<<” “<<&s<<endl;
int i = 0;
int j = 1;
cout<<&i<<” “<<&j<<endl;
cout<<&d_<<” “<<&s_<<endl;
return 0;
}
解决方案
40
d 和 s 都是局部变量,被分配在栈上,它们分别指向堆上的不同对象