运算符new将内存初始化为零
有这样的代码:
#include <iostream>
int main(){
unsigned int* wsk2 = new unsigned int(5);
std::cout << "wsk2: " << wsk2 << " " << *wsk2 << std::endl;
delete wsk2;
wsk2 = new unsigned int;
std::cout << "wsk2: " << wsk2 << " " << *wsk2 << std::endl;
return 0;
}
结果:
wsk2: 0x928e008 5
wsk2: 0x928e008 0
我读过new没有用零初始化内存。但似乎它确实如此。它是如何工作的?
侃侃尔雅
摇曳的蔷薇
相关分类