我试图学习 C++ 中的动态内存分配。我的程序可以编译并运行,但 Visual Studio 向我抛出这些警告。
他们的意思是什么?
Warning C28193 'ptr' holds a value that must be examined.
Warning C28182 Dereferencing NULL pointer. 'ptr' contains the same NULL value as
'new(1*4, nothrow)'
Run Code Online (Sandbox Code Playgroud)
我的代码:
#include <iostream>
#include <cstdint>
int main()
{
int* ptr = nullptr;
if (!ptr) {
ptr = new (std::nothrow) int32_t;
*ptr = 10;
}
std::cout << *ptr << "\n";
}
Run Code Online (Sandbox Code Playgroud) c++ warnings pointers new-operator dynamic-memory-allocation