The phenomenon of one:
The three code output how explanation?
#include
#include
Int main ()
{
Int b;
Int a;
Printf (" % x \ n ", & amp; A);//only output a address, I on the machine for 61 fe1c
system("pause");
return 0;
}
#include
#include
Int main ()
{
Int b;
Int a;
Printf (" % x \ n ", & amp; B);//output b address, only my machine also fe1c for 61
system("pause");
return 0;
}
#include
#include
Int main ()
{
Int b;
Int a;
Printf (" % % x x \ t \ n ", & amp; A, & amp; B);//output at the same time a and b address, my machine is 61 fe18 61 fe1c
system("pause");
return 0;
}
Why the front two output will address the same?
The phenomenon of two:
The two how to explain the code?
#include
#include
Int main ()
{
int b;
int a;
Printf (" a=% d \ n ", a);//output a=16
Printf (" \ n b=% d ", b);//output b=0
Printf (" % X \ n ", & amp; A);//a address is 61 fe18
system("pause");
return 0;
}
#include
#include
Int main ()
{
int b;
int a;
Printf (" a=% d \ n ", a);//output a=0
Printf (" \ n b=% d ", b);//output b=16
Printf (" % X \ n ", & amp; B);//address for 61 b fe18
system("pause");
return 0;
}
From a and b can be seen the value of the exchange of a, b address exchanged? Why a, b will address exchange?
The phenomenon of three:
How do you explain these two code results
#include
#include
Int main ()
{
Int b=10000;
Int a;
Printf (" % X \ n ", & amp; B);//address is 61 b fe1c
system("pause");
return 0;
}
#include
#include
Int main ()
{
Int b=10000;
Int a;
Printf (" a=% d \ n ", a);
Printf (" % X \ n ", & amp; B);//address is 61 b fe18
system("pause");
return 0;
}
Why this two b address changed?
CodePudding user response:
Int x this is stated but no initialization so no assigned addressCodePudding user response:
Assigned address program is run, you run twice, each time you run a same address don't be surprised, at the same time the output is not the sameCodePudding user response:
First of all, each time you run the program, the address is not necessarily the same, if the interval is very short run twice, are assigned in the same address, not surprisingly,And you two pieces of code defines a and b, but only one is used, the compiler may have another variable void, so whether you look at which the address of the variable, because it is used, also showed the same address,
In addition, cannot use uninitialized variable value to what to do, because it is not affirmatory,
CodePudding user response: