ProgrammingModerateTCS NQT · Wipro
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
unsigned x = 40;
int c = 0;
while (!(x & 1u)) { x >>= 1; c++; }
printf("%d", c);
}- A. 3
- B. 5
- C. 2
- D. 4
Correct answer: A. 3
40 = 101000 in binary, which has three trailing zeros. Counting the set bits instead would give 2.
More C Programming questions
- What is printed? c #include <stdio.h> int main(void) { int a[] = {1, 2, 2, 3, 1, 4}; int c = 0; for (int i = 0; i < 5; i++) if (a[i] < a[i…
- For uint32t a = 5 and b = 3, how many of these statements are true? (i) a - b > a (ii) (a - b) + b == a (iii) ~a == UINT32MAX (iv) a / b b…
- What is printed? c #include <stdio.h> int main(void) { int a[3][4]; for (int i = 0; i < 3; i++) for (int j = 0; j < 4; j++) a[i][j] = i 4…
- What is printed? Assume unsigned int is 32 bits. c #include <stdio.h> int main(void) { unsigned x = 0xABCD; printf("%u", (x >> 5) & 7u); }
- What is printed? c #include <ctype.h> #include <stdio.h> int main(void) { const char s = "Hello World"; int n = 0; for (const char p = s…
- What is printed? Assume int is 4 bytes and a pointer is 8 bytes. c #include <stdio.h> int main(void) { printf("%zu", sizeof(int[10]) /…