142k views
1 vote
If you are using an older compiler that does not support the C++ 11 standard, you should initialize pointers with ________.

A) the integer 0, or the value NULL
B) the null terminator '\0'
C) a nonzero value
D) All of these
E) None of these

User Skofgar
by
8.8k points

1 Answer

4 votes

Final answer:

When using an older compiler that does not support C++11, pointers should be initialized with the integer 0 or the value NULL to avoid dangling pointers. NULL makes the intention clear that the variable is a pointer.

Step-by-step explanation:

If you are using an older compiler that does not support the C++ 11 standard, you should initialize pointers with the integer 0, or the value NULL. Prior to C++11, it was common practice to use either 0 or NULL when initializing a pointer to ensure that it pointed to no location, thus avoiding a dangling pointer and potential undefined behavior. While the null pointer constant NULL is typically defined as 0 in C++, using NULL can make it more explicit that the initialized variable is intended to be a pointer.

It is not advisable to initialize a pointer with the null terminator '\0' as this is a character literal and not a pointer value. Similarly, initializing a pointer with a nonzero value is dangerous unless that value is a valid memory address that the pointer is intended to address, which is generally not the case during initialization.

User Nasch
by
8.4k points