How to declare pointer?

closed account (zybCM4Gy)
I simply want to know what is the right way of declaring a pointer.

1
2
    int *ptr1; //This is vulnerable.
    int *ptr2 = 0; //This is wrong. 


Mostly because I keep getting "warning: zero as null pointer constant". Which means that it's not entirely legal and I'm not certain whether I should initialize it as null or nullptr.

Yes I'm using C++11.

Thanks
closed account (zybCM4Gy)
Interesting C++98 is a little bit difficult here, so I'm not sure how I should declare a pointer in C++98 but I am sure in C++11.

In which case a ptr should be defined as

 
    int *ptr1 = nullptr;


Sauce: https://stackoverflow.com/a/7016898
Last edited on
Note that it's a warning, not an error. The warning can probably be disabled in your compiler.
Topic archived. No new replies allowed.