ProgrammingModerateTCS NQT · Infosys
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; if (a + b > 0) printf("P"); else printf("N"); printf("%d", (int)(a + b)); return 0; }
- A. N-2
- B. P4294967294
- C. N2
- D. P-2
Correct answer: D. P-2
b is converted to unsigned, so a + b is the unsigned value 4294967294, which is greater than 0 and prints P. Converting it back to int gives -2.
More C Programming questions
- 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));
- What is printed? int f(int n) { static int c = 0; c += n; if (n <= 0) return c; int r = f(n - 1); return r + c; } printf("%d", f(3));
- What does this C program print? unsigned int x = 0xB5; printf("%x", x ^ (x >> 1));