Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How gets an #if Preprocessor conditional which contains a variable resolved without producing an error?

How does an #if Preprocessor stage statement which contain variable of compile time get resolved at preprocessor stage itself?

Below is the code which runs without any error:

#include<stdio.h> 

void main()
{
   int num=10; /* compile time */

#if((num%2)==0)  /* #if is preprocessor stage but has num of compile time why not error here? */
   printf("\nNumber is Even");
#else
   printf("\nNumber is Odd");
#endif 
}
like image 651
pravu pp Avatar asked Apr 26 '26 07:04

pravu pp


1 Answers

For the evaluation in #if, the preprocessor replaces all identifiers that are already defined macros by their appropriate expansion. All identifiers that remain after that have the value 0.

like image 134
Jens Gustedt Avatar answered Apr 28 '26 23:04

Jens Gustedt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!