Suppose I have a main function as below:
void main()
{ int *p;
p = foo(31);
printf(“%d”, (*p)+2);
bar(7); /* Body of function bar() not shown */
printf(“%d”, (*p)+4);
}
int *foo(int x)
{
return &x;
}
Assuming the function bar() that compiles correctly, why the second result of the printf is 11 if the body of bar() does not write to its incoming arguments space.
More specifically, my question is why the incoming argument value of bar() which is 7 replaces the value 31?
What's more, when the main function pass the value 31 into foo(), how does the value 31 passed? By register? or the compiler creates a temporary variable to pass 31? And why the incoming argument of foo() and bar() share the same position in the memory