Whats better to use in C++11 , Zero or NULL?

前端 未结 4 1224
陌清茗
陌清茗 2021-02-04 05:19

Nowadays, with C++11, Whats recommended to use, Zero or NULL? The first of the second if?

int * p = getPointer();

if( 0 == p ){
    //         


        
4条回答
  •  -上瘾入骨i
    2021-02-04 05:29

    If you have the same problem in 2019, You are using an older initialization style for unassigned pointers. After 2014 August 14 the C++ 11 released. The compiler you are using is probably following the C++11 standard.

    You can just replace 0/NULL with nullptr

    Modern C++ offers nullptr as a universal null pointer. You should use that instead of 0 || NULL because there are some obscure machines that have things like signed pointers where a null pointer is actually something like -1 rather than 0.

提交回复
热议问题