paizza paizza - 1 year ago 56
C++ Question

Which "value" has an un-init value?

I've this code:

double val1;
double val2 = 0.0;

if(val1 != val2) {
cout << "different: " << val1 << " | " << val2 << endl;

which enter to the
. I think that
doesn't get 0.0 by default (i.e. NULL). Which value does it get so? I always thought 0.0 was by default...

Answer Source

Local non-static variables that are not initialized will have an indeterminate value, and it will be seemingly random.

You should not use uninitialized local variables as that leads to undefined behavior.