本文介绍了关于变量的重新声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已将变量声明为int x并编译了程序,当我从程序中删除此变量,并且在编译后我再次重新声明了与int x相同的变量,那么该变量的地址将在内存中相同在重新声明期间?并且地址是否更改,为什么?
I have declared a variable as int x and i compiled the program and when i delete this variable from the program and after compilation i again redeclare the same variable as int x, then will the address be same for this variable in the memory during redeclaration?and if the address changes ,why is it?
推荐答案
// Stack address: 0000100
for(int i=0;i<10;i++){ /*something */ } // Stack address: 00000FC
// Stack address: 0000100
// do anything else
for(int i=0;i<10;i++){ /*something */ } // Stack address: 00000FC
// Stack address: 0000100
您可以看到-该程序在堆栈上重用了相同的地址.
或以另一种方式
You can see - the program reuses the same address on the stack.
Or in another way
void function(int x,int y)
{
if(1==x)
{
int a;
// do...
}
if(1==y)
{
int z; // <- ''z'' uses the same adress as ''a'' before
}
}
问候.
这篇关于关于变量的重新声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!