小编Bor*_*sko的帖子

我可以对C++本地变量地址做出什么假设

我想知道,如果我可以重用指针到循环块内的变量.

int *ptr = nullptr;
for (int i = 0; i < 5; ++i) {
    int j = 5;
    if (!ptr) ptr = &j;
    cout << *ptr << endl;
}
Run Code Online (Sandbox Code Playgroud)

我相信这段代码适用于所有编译器,但它是否符合标准?

c++ scope lifetime

4
推荐指数
1
解决办法
132
查看次数

标签 统计

c++ ×1

lifetime ×1

scope ×1