更正:
我搞砸了指针地址的概念和指针指向的地址,因此修改了以下代码.现在它打印出我想要的东西,变量a,c,i,j,k,p在堆栈上,变量b,d在堆上.静态和全局变量在另一个段上.非常感谢大家!
嗯,我知道这两个概念已经深入讨论了......但是我仍然对以下代码有疑问:
#include <iostream>
using namespace std;
class A {
};
int N = 10;
void f(int p) {
int j = 1;
float k = 2.0;
A c;
A* d = new A();
static int l = 23;
static int m = 24;
cout << "&c: " << &c << endl;
cout << "&d: " << d << endl;
cout << "&j: " << &j << endl;
cout << "&k: " << &k << endl;
cout << "&l: …Run Code Online (Sandbox Code Playgroud)