I had this question in a test, and I still don't understand the answer I was given:
Let's say I wrote the following code:
#include <math.h>
#include <stdio.h>
float cos(float x){
return 1-x*x/4;
}
int main()
{
printf("%0f",cos(0.05f)+sin(0.05f));
}
Let's assume cos
and sin
are declared and defined in the math library (receiving and returning double
), and I'm trying to link my code with the math library.
Another assumption is that cos
is defined in math.c
.
The question was:
"Will the code compile/link successfully? if so, which cos function will be called?"
The answer was:
"Yes, the code will compile and my cos will be called".
How could this behavior be explained? Aren't these multiple definitions of the same function?