ProgrammingVery hardTCS NQT · Infosys
What is printed? Assume uint16t is 16 bits.
What is printed? Assume uint16_t is 16 bits.
#include <stdint.h>
#include <stdio.h>
int main(void) {
uint16_t a = 0xFFF0, b = 0x20;
uint16_t s = a + b;
int carry = s < a;
printf("%d %d", s, carry);
}- A. 16 0
- B. 65520 1
- C. 16 1
- D. 240 1
Correct answer: C. 16 1
a + b = 0x10010 wraps to 0x0010 = 16 in a 16-bit type, and the wrap shows as s < a, which is true.
More C Programming questions
- What is printed? c #include <stdio.h> long long f(int n) { return n == 0 ? 1 : 2 f(n - 1) + 1; } int main(void) { printf("%lld", f(10)); }
- What is printed? c #include <stdio.h> int main(void) { printf("%d", 1000 >> 3); }
- What is printed? c #include <stdio.h> int main(void) { int c = 0; switch (3) { default: c += 1; case 1: c += 10; } printf("%d", c); }
- What is printed? c #include <stdio.h> int main(void) { printf("%d", 1 ? 2 : 3 ? 4 : 5); }
- What is printed? c #include <stdio.h> int main(void) { printf("%d", (1, 2)); }
- What is printed? c #include <stdio.h> int main(void) { char c = 'a'; printf("%d", c++ == 'a' && c == 'b'); }