这些 nullptr 位于何处?
Where are these nullptr located?
int* x = nullptr;
class_example* obj = nullptr;
我明白什么是 nullprt,但是这些变量 x 和 obj 位于何处?
堆?还是堆叠?
指针只是普通变量,恰好有 值 是其他对象的地址(这些地址可能在堆上)。
所以在这个片段中:
int main()
{
int* x = nullptr;
class_example* obj = nullptr;
}
就像常规局部变量一样,这些指针将位于堆栈上。
int* x = nullptr;
class_example* obj = nullptr;
where are these variables x and obj located?
这些变量具有静态存储持续时间,因为它们是在没有 thread_local 关键字的命名空间范围内声明的。语言标准没有指定对象的位置。由语言实现来决定。
Heap? or Stack?
通常两者都不会。
例如,在 ELF 可执行格式中,零个初始化的静态变量将位于名为 BSS 的内存段中。
int* x = nullptr;
class_example* obj = nullptr;
我明白什么是 nullprt,但是这些变量 x 和 obj 位于何处?
堆?还是堆叠?
指针只是普通变量,恰好有 值 是其他对象的地址(这些地址可能在堆上)。
所以在这个片段中:
int main()
{
int* x = nullptr;
class_example* obj = nullptr;
}
就像常规局部变量一样,这些指针将位于堆栈上。
int* x = nullptr; class_example* obj = nullptr;
where are these variables x and obj located?
这些变量具有静态存储持续时间,因为它们是在没有 thread_local 关键字的命名空间范围内声明的。语言标准没有指定对象的位置。由语言实现来决定。
Heap? or Stack?
通常两者都不会。
例如,在 ELF 可执行格式中,零个初始化的静态变量将位于名为 BSS 的内存段中。