ProgrammingHardTCS NQT · Accenture
What is printed? The hexadecimal literal is 0x1F and the comparison is with 31.
What is printed? The hexadecimal literal is 0x1F and the comparison is with 31.
#include <stdio.h>
int main(void) {
printf("%d", 0x1F == 31);
}- A. 0
- B. 2
- C. 3
- D. 1
Correct answer: D. 1
0x1F = 1 x 16 + 15 = 31, so the comparison is true, and == always yields the int 1 (or 0). Answers like 2 or 3 confuse the comparison result with some other value.
More C Programming questions
- 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…
- What does this program print? #include <stdio.h> int main(void) { int a[] = {10, 20, 30, 40, 50}; int p = a + 1; int v = p++; int w = ++p…
- What does this C program print? unsigned char a = 200, b = 100; printf("%d %d", a + b > 255, (unsigned char)(a + b) > 255);
- What does this C program print? int a[2][3] = {{1,2,3},{4,5,6}}; int (p)[3] = a; printf("%d %d", ((p+1))[1], (p+1) + (p+2));
- What does this C program print? #define SQ(x) xx printf("%d", SQ(2+3) / SQ(1+1));