ProgrammingVery hardTCS NQT · Infosys
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
unsigned char a = 100, b = 200;
unsigned char s = (unsigned char)(a + b) / 2;
printf("%d", s);
}- A. 150
- B. 172
- C. 100
- D. 22
Correct answer: D. 22
a + b is 300 in int, but the cast to unsigned char wraps it to 44 before the division, giving 22. Dividing first would give 150.
More C Programming questions
- How many times does the loop body run? c #include <stdio.h> int main(void) { int c = 0; for (int i = 0, j = 0; i < 4 && j < 4; i++, j +=…
- What is printed? c #include <stdio.h> void inc(int p, int n) { while (n--) (p++)++; } int main(void) { int a[] = {1, 2, 3}; inc(a, 2)…
- What is printed? c #include <stdio.h> int main(void) { unsigned short s = 1; s <<= 15; printf("%d", s); }
- What is printed? c #include <stdio.h> int main(void) { printf("%d", 'a' < 'b' && 'b' < 'c'); }
- char d[4]; char s[] = "abc"; strncpy(d, s, sizeof d - 1); d[sizeof d - 1] = '0'; printf("%s", d); What is printed?
- char w[16]; scanf("%15s", w); Why is the width 15 used?