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 125 views
125 views asked May 13, 2021 by avibootz
1 answer 146 views
1 answer 133 views
2 answers 253 views
2 answers 173 views
173 views asked May 5, 2017 by avibootz
...