欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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.