Default pointer value in Visual C ++ 6.0

What is the default for a pointer in Visual C ++ 6.0.

If this is important, my question pertains in particular to variables on the stack.

In this case, would myArray initially be a NULL pointer, or would it be undefined?

double* myArray;

      

+2


source to share


6 answers


Undefined.
C ++ does not define a default for uninitialized pointers.

If you run debugging with visual studio then the initial value of uninitialized variables is sometimes something like 0xcdcdcdcd. This value changes depending on whether the variable is on the stack or on the heap. This is, however, not true in release builds, and you should not rely on it in any way.



Here's more information about these values.

+6


source


It's rubbish.



+2


source


It's undefined. And even if VC ++ 6.0 is absolutely guaranteed to use a certain value, it will still be undefined by the C ++ standard. You should always avoid special compiler functions. You may not feel like you need to move the code to another compiler, but sooner or later you will and it will break.

And it's so hard to say:

double* myArray = NULL;

      

+2


source


your myArray will be garbage value

0


source


There is no default pointer value in Visual C ++. If not declared, the pointer is not initialized, so the value will be undefined (which means garbage). Therefore, it is recommended as a best practice to initialize pointers at declaration (or in the constructor initialization list for class pointer members).

0


source


A pointer is determined at run time to occupy some specific place in memory. Its initial value will be determined by whatever bit pattern happens to be at that location. It is impossible to define it in advance.

As stated elsewhere, declare it with an initial value of null, or in whatever way you like.

0


source