ProgrammingModerateInfosys · Wipro
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
int x = 6;
printf("%d", x & -x);
}- A. 2
- B. 6
- C. 4
- D. 8
Correct answer: A. 2
x & -x keeps only the lowest set bit of 6 = 110, which is 10 = 2. The value 4 is the highest set bit, not the lowest.
More C Programming questions
- What is printed? c #include <stdio.h> int main(void) { const char s = " a bb ccc "; int words = 0, in = 0; for (; s; s++) { if (s == ' ')…
- What is printed? c #include <stdio.h> int ways(int n) { if (n == 0) return 1; if (n < 0) return 0; return ways(n - 1) + ways(n - 3); } int…
- What is printed? c #include <stdint.h> #include <stdio.h> uint64t pw(uint64t b, uint64t e, uint64t m) { uint64t r = 1; b %= m; while (e) {…
- What is printed? c #include <stdio.h> int main(void) { unsigned char comp[51] = {0}; int count = 0; for (int i = 2; i <= 50; i++) { if…
- What is printed? c #include <stdio.h> int main(void) { int s = 0; for (int i = 0; i < 10; i++) { if (i % 3 == 0) continue; if (i > 7)…
- What is printed? c #include <stdio.h> int main(void) { printf("%d %d", sizeof(char) < -1, -1 < 0); }