I am learning C using Visual Studio 2015. If I create a brand new project and execute nothing other than the following code:
#include <stdio.h>
int main()
{
#if abc == xyz
printf("Expression is true.");
#else
printf("Expression is false.");
#endif
}
the application prints out the string Expression is true
which is something I was not expecting. The reason I was not expecting this to work like this is because I was expecting a compile error given that the abc
and xyz
tokens are not defined or declared anywhere in code. So the question is why is this working?
Finally, if I declare and define abc
and xyz
as follows:
int abc = 123;
int xyz = 456;
the application prints out the string Expression is true
? This looks clearly wrong doesn't it? Why is it that if I declare and define the variables as integers with different values I trigger the #if and not the #else?
Thank you.