ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
#include <stdint.h>
#include <stdio.h>
int main(void) {
uint32_t a = 0xFFFFFFF0u, b = 0x20u;
uint32_t s = a + b;
int carry = s < a;
printf("%u %d", s, carry);
}- A. 16 0
- B. 4294967312 1
- C. 16 1
- D. 240 1
Correct answer: C. 16 1
a + b wraps modulo 2^32 to 16, and the wrap is detected by s < a, which is true. The unreduced 4294967312 can never be stored in uint32_t.
More C Programming questions
- What is printed? c #include <stdint.h> #include <stdio.h> int main(void) { int16t a = 200, b = 200; int p = a b; printf("%d %d", p, p >…
- What is printed? c #include <stdint.h> #include <stdio.h> uint16t sat(uint16t a, uint16t b) { uint32t p = (uint32t)a b; return p > 65535u…
- What is printed? c #include <stdio.h> int main(void) { int m[4][4]; for (int i = 0; i < 4; i++) for (int j = 0; j < 4; j++) m[i][j] = i 4…
- How many pairs (i, j) with i < j satisfy a[i] < a[j] for a = {3, 1, 4, 2}? Compute with this program. c #include <stdio.h> int main(void)…
- What is printed? c #include <stdio.h> int main(void) { int a[] = {1, 2, 3}, cnt[3], total = 0; for (int i = 0; i < 3; i++) { cnt[i] = 1…
- How many binary strings of length 5 contain no two adjacent 1s? Compute with this recursive program. c #include <stdio.h> int f(int n) {…