Monday 18 March 2013

#define FALSE -1 #define TRUE 1 #define NULL 0


#define FALSE -1
    #define TRUE   1
    #define NULL   0
    main() {
       if(NULL)
         puts("NULL");
       else if(FALSE)
         puts("TRUE");
       else
         puts("FALSE");
       }
Answer:
TRUE
Explanation:
The input program to the compiler after processing by the preprocessor is,
    main(){
         if(0)
             puts("NULL");
    else if(-1)
             puts("TRUE");
    else
             puts("FALSE");
         }
Preprocessor doesn't replace the values given inside the double quotes. The check by if condition is boolean value false so it goes to else. In second if -1 is boolean value true hence "TRUE" is printed.

Blog Author: Vijay Kumar

Go to: Java Aptitude


No comments:

Post a Comment