ProgrammingVery hardTCS NQT · Infosys
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
int a = 2, b = 3;
printf("%d", a ^ b == 1);
}- A. 1
- B. 0
- C. 2
- D. 3
Correct answer: C. 2
== binds tighter than ^, so the expression is a ^ (b == 1) = 2 ^ 0 = 2. Reading it as (a ^ b) == 1 gives 1, the tempting wrong answer.
More C Programming questions
- What is printed? c #include <stdio.h> int main(void) { printf("%d", !!(0x80) + !0 + !-1); }
- What is printed? c #include <stdio.h> int main(void) { printf("%d", 5 % -3); }
- What is printed? c #include <stdio.h> #include <string.h> int main(void) { printf("%d", strlen("hello") > 4 ? 1 : 0); }
- What is printed? Assume int is 4 bytes. c #include <stdio.h> int main(void) { printf("%d", (int)sizeof(char[3][4])); }
- What is printed? The hexadecimal literal is 0x1F and the comparison is with 31. c #include <stdio.h> int main(void) { printf("%d", 0x1F ==…
- What is printed? c #include <stdio.h> int main(void) { unsigned char c = 255; c += 1; printf("%d", c); }