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

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -