ProgrammingHardTCS NQT · Wipro
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
printf("%d", !!(0x80) + !0 + !-1);
}- A. 3
- B. 1
- C. 0
- D. 2
Correct answer: D. 2
!0x80 is 0, so !!0x80 normalises the nonzero value to 1; !0 is 1 and !-1 is 0 because any nonzero value is true. The total is 2, and 3 wrongly treats !-1 as 1.
More C Programming questions
- 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); }
- Assume int and unsigned int are 32-bit. What does this program print? #include <stdio.h> int main(void) { unsigned int a = 3; int b = -5…