I wrote this code:
#include<stdio.h>
int valFunc(int val){
return val;
}
int main(){
int a = 5;
int b = 7;
printf("%d",valFunc(a)+valFunc(b));
return 0;
}
Inside the printf() function of main(), after valFunc(a) gets called and returns the value as 5, where does the main function save this value 5 before calling valFunc(b)?
I know that if this function was written like below, then it would have saved the returned values of the functions valFunc(5) and valFunc(7) in integer variables a and b respectively. :
#include<stdio.h>
int valFunc(int val){
return val;
}
int main(){
int a = valFunc(5);
int b = valFunc(7);
printf("%d",a+b);
return 0;
}
But in the former code, I am unable to understand where does the function save the returned values? Does it create implicit variables and uses them to save its progress before calling other functions or is there some other mechanism? Please explain.
Does it create any temporary variables to store these values on the runtime stack before calling the other functions? In the second code that I have written in the question, its clear that main() will store these values in a and b and put them on the runtime stack. But how main() will do this for the first code as there are no variables?