#include<stdio.h>
int main(){
int a =1;
#if(a==0)
printf("equal");
#else if
printf("unequal");
#endif
return -1;
}
which you pass to the compiler will first go through the preprocessor whose output is then sent as an input to the compiler; the preprocessor will send
#include<stdio.h>
int main(){
int a =1;
printf("equal");
return -1;
}
to the compiler, which is the reason you see equal
always. The reason is since a
as a macro is undefined, the first condition is true, there by leading to only passing that statement on to the compiler. If you try adding #define a 1
next to the include directive, then you'll always see unequal
as an output; but these changes affect only the compile time macro a
and not the runtime variable a
(both are entirely different).
All this because preprocessor is concerned only with compile-time constructs. What you really need may be
#include<stdio.h>
int main(){
int a =1;
if(a == 0)
printf("equal");
else
printf("unequal");
return 0;
}
Aside: Return 0 when you're program is successful, returning negative values from main usually means some error state termination of your program.