No compiler/runtime error?
This is definitely a newbie question. I've got a very simple example where I expected to get a compile or runtime error, but it actually works, albeit with the wrong answer:
Code:
#include <stdio.h>
int square(int x) {
return x*x;
}
int main() {
float a = 12.5;
int b = square(a);
printf("%f^2 = %d\n", a, b);
return 0;
}
If I compile it and run it, I get the following:
It's the wrong answer and the wrong data type for the function call, but the C compiler allows it. Can someone point me to a reason?
Many thanks!