delete 数组后 指针是否为null 博客分类: c++
程序员文章站
2024-03-19 10:59:58
...
/** \brief 测试 delete 数组指针后,数组指针是否为 nullptr * 测试结果: delete 数组指针后, 数组指针不为 nullptr * * \param * \param * \return * */ #include <iostream> using std::cout ; int main(){ int * ary = new int [100]; if(ary == nullptr) cout << "ary == nullptr \n"; else { cout << "ary pointer is not nullptr.\n"; } ary[1] = 1l; ary[2] = 12; delete [] ary; ary = nullptr; if(ary==nullptr) cout << "ary == nullptr \n"; else { cout << "ary pointer is not nullptr.\n"; } return 0; }
ary pointer is not nullptr. ary == nullptr Process returned 0 (0x0) execution time : 0.004 s Press ENTER to continue.
上一篇: Java 随机生成一个范围内的数