ProgrammingModerateTCS NQT · Infosys
What is printed?
What is printed?
unsigned v = 0;
const char *b = "10110";
while (*b) v = (v << 1) | (*b++ - '0');
printf("%u", v);- A. 11
- B. 13
- C. 44
- D. 22
Correct answer: D. 22
Each step shifts the value left and appends the next binary digit (character minus '0'): 1, 10, 101, 1011, 10110 = 22. '13' reads the digits in reverse order (01101); '44' shifts once too often.
More C Programming questions
- With 4-byte int, what is printed? c int a[2][3][4]; printf("%zu %zu %td", sizeof a[1], sizeof a[1][2], (char )&a[1][2][3] - (char )a);
- Assume ASCII. What is printed? c int my(const char a, const char b) { while (a && a == b) { a++; b++; } return a - b; } int main(void) {…
- In what order are the nodes linked after the four calls? c struct N { int v; struct N nx; }; void ins(struct N h, struct N n) { while (h…
- A function in a.c is declared static int helper(void) { ... }. Which statement is true?
- What is printed? c #define MAX(a, b) a > b ? a : b int x = 3, y = 7; printf("%d", 2 MAX(x, y));
- Assume IEEE-754 single-precision float with float arithmetic done in float. Which loops terminate? c int c1 = 0, c2 = 0; for (float f = 0…