Y
ypjofficial
Hello All,
since the programs' stack is shared among all the function inside the
program,
I was just doing some R&D to see whether the same stack space is used
for the variables inside the different functions are not.
below is my code
//program start
void fun1()
{int i;
cout<<&i;
}
void fun2()
{
int i;
cout<<&i;
}
int main()
{
fun1();
fun2();
}
//program end
Both gave the same output(address of local variable i) since the same
stack space is used.
//output is
0x0012FF24 //output from fun1
0x0012FF24 //output from fun2
But i get the different results when I make following chang in one of
the function.
void fun1(int i)
{
cout<<&i;
}
and inside main i call it as fun1(4)
but now the output is different.
//output is
0x0012FF2C //output from fun1
0x0012FF24 //output from fun2
So far I was thinking that since the function parameters are also
passed onto the stack, I should get the same output(same address for
both the local version of i).
I am using MSVC6.0
what could be the reason for this different output?
Thanks and Regards,
Yogesh Joshi
since the programs' stack is shared among all the function inside the
program,
I was just doing some R&D to see whether the same stack space is used
for the variables inside the different functions are not.
below is my code
//program start
void fun1()
{int i;
cout<<&i;
}
void fun2()
{
int i;
cout<<&i;
}
int main()
{
fun1();
fun2();
}
//program end
Both gave the same output(address of local variable i) since the same
stack space is used.
//output is
0x0012FF24 //output from fun1
0x0012FF24 //output from fun2
But i get the different results when I make following chang in one of
the function.
void fun1(int i)
{
cout<<&i;
}
and inside main i call it as fun1(4)
but now the output is different.
//output is
0x0012FF2C //output from fun1
0x0012FF24 //output from fun2
So far I was thinking that since the function parameters are also
passed onto the stack, I should get the same output(same address for
both the local version of i).
I am using MSVC6.0
what could be the reason for this different output?
Thanks and Regards,
Yogesh Joshi