This is pretty simple, yet I cannot explain it. I declare 4 variables, and print it out in C++:
#include <iostream>
using namespace std;
int main(){
int a, b, c, d;
cout << "a = " << a << endl;
cout << "b = " << b << endl;
cout << "c = " << c << endl;
cout << "d = " << d << endl;
return 0;
}
And the result is:
a = 0
b = 1
c = 0
d = 0
I thought if I don't initialize value for a variable, the program will take some random value from the memory for it. Or at least it's all equal to zero. I don't know where the difference of those values come from.
This is not because of a specific variable b
, if I switch those "cout <<" lines, the second line always give the value = 1.
Can anyone explain this for me, please. Thank you so much.