ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
int a = 2147483647;
printf("%u", (unsigned)a + 1u);
}- A. 2147483647
- B. 2147483648
- C. 0
- D. 4294967295
Correct answer: B. 2147483648
The conversion keeps the value 2147483647, and adding 1u gives 2147483648, which fits in unsigned int. Adding 1 as a signed int would overflow, which is undefined, so the unsigned form is the one that is well defined.
More C Programming questions
- How many integers from 1 to 64 have their low three bits all clear? Compute with this program. c #include <stdio.h> int main(void) { int c…
- How many times does the letter g occur in "programming"? The program counts it with a pointer walk. c #include <stdio.h> int main(void) {…
- What is printed? c #include <stdio.h> int main(void) { int x = 10; printf("%d %d", x & -x, x & (x - 1)); }
- What is printed? c #include <stdio.h> int main(void) { int v[] = {3, 9, 4}; int p = v; int s = 0; while (p < v + 3) s += p++ 2…
- What is printed? c #include <stdio.h> int main(void) { printf("%c", 'Z' - 'A' + 'a'); }
- What is printed? c #include <stdio.h> #include <stdlib.h> int nd(int n) { int c = 0; for (int d = 1; d <= n; d++) if (n % d == 0) c++…