When declaring pointers in C or C++, is it prudent to assign them NULL if I'm not going to directly assign them a value as soon as I declare them?
\[\small{\text{void *p = NULL}}\]
I don't think it C do anything like that implicitly.You may like to read further here : http://c-faq.com/~scs/cclass/int/sx7.html
When I used Visual C++ way back in 1998, when running in debug mode it would initialize pointers to 0xcdcdcdcd, and would set deleted pointers to 0xdddddddd. That way when your program broke you could look for pointers with these recognizable values to see which ones you were using improperly. If you leave pointers uninitialized they could be pointing to a valid memory location, and when you use it you could get a valid value, or write a value to it validly. Initializing the pointer to an invalid value won't let that happen, so your program will fail fast, which is good.
Join our real-time social learning platform and learn together with your friends!