I am learning C and was trying to help debug a friends code. He was defining his function parameters in the global scope and then passing them into the function def like so:
#include <stdio.h>
double x;
double myfunc(x){
return x;
}
void main(){
}
I get this is wrong, but not why the following error comes up:
main.c:14:8: warning: type of ‘x’ defaults to ‘int’ [-Wimplicit-int]
Can someone help me understand how the computer is interpreting this code?
He was defining his function parameters in the global scope
No, he does not.
The global x
is unrelated to the function's parameter x
.
The former is a global double
, the latter is local to the function and, as the compiler is warning, "defaults to int
".
I get this is wrong
It is not wrong, but not possible.