小编Zho*_*hou的帖子

C++中Stack和Heap的地址

更正:

我搞砸了指针地址的概念和指针指向的地址,因此修改了以下代码.现在它打印出我想要的东西,变量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)

c++ heap stack

8
推荐指数
1
解决办法
6466
查看次数

标签 统计

c++ ×1

heap ×1

stack ×1