when i run this program the memory address of variables x and y are the same.
my best guess would be that since the variables exist in functions that are called on they only exist when theyre called on so they can use the same memory location. does this make sense?
#include <stdio.h>
void foo1(int);
void foo2(int);
void foo1(int xval)
{
int x;
x = xval;
int *ptr;
ptr = &x;
printf("address of x: %p\n", ptr);
printf("value of x: %d\n", *ptr);
}
void foo2(int yval)
{
int y;
y = yval;
int *ptr;
ptr = &y;
printf("address of y: %p\n", ptr);
printf("value of y: %d\n", *ptr);
}
int main()
{
foo1(7);
foo2(11);
return 0;
}