#include<stdio.h>
void fun(z)
{
printf("%d",z);
}
int main()
{
int a=5;
fun(a);
}
This is giving output as 5. Shouldn't it give an error - undeclared variable z ?
Is this a compiler optimization ?
#include<stdio.h>
void fun(z)
{
printf("%d",z);
}
int main()
{
int a=5;
fun(a);
}
This is giving output as 5. Shouldn't it give an error - undeclared variable z ?
Is this a compiler optimization ?
This is not a compiler optimization, it is a compliance with an ancient C convention that allowed you to skip variable and parameter types when the desired type is int
. This convention pre-dates the ANSI standard, and should be avoided even if your compiler is fine with such code.
You will get a warning if you tell the compiler that you want your code to comply with one of more modern standards, say, C99 or C11. The flag is compiler-dependent. If you are using gcc
, add
-std=c99
flag to see the warning.