How to check if pointer is NULL in C++

1 Answer

0 votes
#include <iostream>

int main() {
    int i = 12;
    int *p = &i;
 
    if (p != nullptr) {
        std::cout << *p;
    }
    else {
        std::cout << "p is NULL";
    }
    
    return 0;
}




/*
run:

12

*/

 



answered May 13, 2021 by avibootz
edited May 13, 2021 by avibootz

Related questions

1 answer 208 views
208 views asked May 13, 2021 by avibootz
1 answer 231 views
1 answer 221 views
2 answers 379 views
2 answers 305 views
305 views asked May 5, 2017 by avibootz
...