c++ - same address for different variables of different functions in c -
while printing address , value of 'x' in function foo1 , address , value of y in foo2, why showing same values both of functions?
#include <stdio.h void foo1(int xval) { int x; x = xval; /* print address , value of x here */ } void foo2(int dummy) { int y; /* print address , value of y here */ } int main() { foo1(7); foo2(11); return 0; }
output of program is
address of x is: 65518
value of x is: 7
address of y is: 65518
value of y is: 7
it's because they're created on stack, unwound after each function call. are created @ same memory address.
Comments
Post a Comment