ProgrammingHardWipro · Cognizant pattern

What is printed?

What is printed?
#define TRUE 1
#define FALSE 0
#define BOOL int
BOOL flag = TRUE;
int main(void) {
    if (flag == TRUE)
        printf("yes");
    else
        printf("no");
}
  1. A. no
  2. B. yes
  3. C. Compilation error: BOOL is not a real type
  4. D. 1

Correct answer: B. yes

These are simple object-like macros: BOOL expands to int, TRUE to 1, FALSE to 0. After expansion the code is ordinary: int flag = 1; if (flag == 1) printf("yes"); which prints "yes".

More C Programming questions

Exams that ask this topic