0

Hi guys

What's the default pointer value in c++? Can I count on the compiler to set an uninitialized pointer to NULL? Is it compiler dependant? What's the "consensus"?

Thanks!
-FH

2
Contributors
2
Replies
25
Views
4 Years
Discussion Span
Last Post by FelineHazard
3

It really depends somewhat on how you declare your pointer. For example, a static or global pointer will be default initialized to null. A local pointer will contain random garbage if not explicitly initialized, just like any other local variable.

Best practice is to initialize your variables in all cases to avoid having to remember and apply the different rules to the given situation.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.