I'm learning C. I have done some little experimentswhen I'm learning some chapters.
The major question is I can't understand why the result of the code's execution is following, because it doesn't meet what I thought code would go.
source code:
#include <stdio.h>
int imax();
int main(void)
{
printf("%zd %zd\n", sizeof(int), sizeof(double));
printf("The maximum of %d and %d is %d.\n", 3, 5, imax(3));
printf("The maximum of %d and %d is %d.\n", 3, 5, imax(3.0, 1000.0));
printf("The maximum of %d and %d is %d.\n", 3, 5, imax(3.0));
printf("The maximum of %d and %d is %d.\n", 3, 5, imax(1000.0));
return 0;
}
int imax(n, m)
int n, m;
{
return (n > m ? n: m);
}
the output:
What I can't understand is why the last three print statements print same words! I know I am do a test for researching what will happen when the declaration of a function using old style which do not care the formal parameters' type. In the context, I design four cases which the calling function's actual arguments do not match with the requirement of the called function's formal parameters.
I know this is relevant to the mechanism of the stack in C. And I try my best to search why. In my opinion, the last three print statements should behave different. In fact, I think the statement imax(3.0, 1000.0) may be same with imax(3.0) or imax(1000.0) but it's impossible be same with both!