What will be the result of #define a 1 or undefined variable # if a==1 in c language

in c language,

#define a 1  
#if a==1  
#define b  
#if b==1

What will be the result?

in conclusion

define #ifdef WAS #if defined(VAR) #if VAR ==1 #if VAR ==0
#define VAR 1 true true true false
#define WAS 0 true true false true
#define WHERE true true ERROR (compilation failed) ERROR
#undefine WAS false false false true
None false false false true
  1. #undefine VAR is equivalent to not defining VAR
  2. #ifdef VAR is equivalent to #if defined(VAR)
  3. Undefined VAR is equivalent to 0
  4. If you want multiple conditions you can
    #if defined(VAR_A) || VAR_B==1
  5. If you want multiple conditions you can
    #if defined(VAR_A) && VAR_B==1

insert image description here

Guess you like

Origin blog.csdn.net/coraline1991/article/details/120313875