给定一个程序:
int main()
{
short myVariableName1; // stores from -32768 to +32767
short int myVariableName2; // stores from -32768 to +32767
signed short myVariableName3; // stores from -32768 to +32767
signed short int myVariableName4; // stores from -32768 to +32767
unsigned short myVariableName5; // stores from 0 to +65535
unsigned short int myVariableName6; // stores from 0 to +65535
int myVariableName7; // stores from -32768 to +32767
signed int myVariableName8; // stores from -32768 to +32767
unsigned int myVariableName9; // stores from 0 to +65535
long myVariableName10; // stores from -2147483648 to +2147483647
long int myVariableName11; // stores from -2147483648 to +2147483647
signed long myVariableName12; // stores from -2147483648 to +2147483647
signed long int myVariableName13; // stores from -2147483648 to +2147483647
unsigned long myVariableName14; // stores from 0 to +4294967295
unsigned long int myVariableName15; // stores from 0 to +4294967295
cout << "Hello World!" << endl;
cout << myVariableName1 << endl;
cout << myVariableName2 << endl;
cout << myVariableName3 << endl;
cout << myVariableName4 << endl;
cout << myVariableName5 << endl;
cout << myVariableName6 << endl;
cout << myVariableName7 << endl;
cout << myVariableName8 << endl;
cout << myVariableName9 << endl;
cout << myVariableName10 << endl;
cout << myVariableName11 << endl;
cout << myVariableName12 << endl;
cout << myVariableName13 << endl;
cout << myVariableName14 << endl;
cout << myVariableName15 << endl;
cin.get();
return 0;
}
打印出未分配的变量将打印之前存储在该内存位置中的任何内容。我注意到的是,在多次连续执行中,打印的值没有改变——这告诉我每次执行时内存中的位置都是相同的。
我只是好奇这是如何确定的,为什么会这样。