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");
}- A. no
- B. yes
- C. Compilation error: BOOL is not a real type
- 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
- What is printed? c #define CLAMP(x, lo, hi) ((x) < (lo) ? (lo) : (x) > (hi) ? (hi) : (x)) int main(void) { printf("%d %d %d", CLAMP(5, 1…
- What is printed? Assume int is 32-bit, two's complement. c int x = INTMAX; int y = x + 1; printf("%d", y);
- What is the behavior? c int p = malloc(10 sizeof(int)); free(p); printf("%d", p[0]);
- What is printed? c int i = 1; int arr[5] = {0}; int x = i + i++; printf("%d", x);
- What is the behavior? c int arr[5] = {1,2,3,4,5}; int p = arr + 5; printf("%p", (void)p); printf("%d", p);
- What is the behavior? c char buf[5]; strcpy(buf, "hello world"); printf("%s", buf);