ProgrammingHardCompetitive coding (CP)
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
int x = 10;
printf("%d %d", x & -x, x & (x - 1));
}- A. 2 8
- B. 2 10
- C. 8 2
- D. 4 8
Correct answer: A. 2 8
x & -x keeps the lowest set bit of 1010, which is 2, and x & (x - 1) clears that bit, leaving 1000 = 8.
More C Programming questions
- What is printed? c #include <stdio.h> int main(void) { int v[] = {3, 9, 4}; int p = v; int s = 0; while (p < v + 3) s += p++ 2…
- What is printed? c #include <stdio.h> int main(void) { printf("%c", 'Z' - 'A' + 'a'); }
- What is printed? c #include <stdio.h> #include <stdlib.h> int nd(int n) { int c = 0; for (int d = 1; d <= n; d++) if (n % d == 0) c++…
- How many binary strings of length 4 have exactly two 1s? The program counts them recursively. What is printed? c #include <stdio.h> int…
- What is printed? c #include <stdio.h> int v[] = {1, 2, 3}; int cnt(int i, int s) { if (i == 3) return s % 2 == 0; return cnt(i + 1, s) +…
- What is printed? c #include <stdio.h> int used[3]; int count(int d) { if (d == 3) return 1; int t = 0; for (int i = 0; i < 3; i++) { if…