ProgrammingVery hardGATE CS · Campus placements
int x = 0; for (int i = 0; i < 5; i++) x = x ^ i << 1; What is x at the end?
- A. 8
- B. 2
- C. 6
- D. 0
Correct answer: A. 8
<< binds tighter than ^, so each step XORs x with i shifted left by one: the values run 0, 2, 6, 0, 8. The final value is 8.
More C Programming questions
- uint16t a = 300, b = 300; uint16t p = a b; What is p?
- What does printf("%d", strcmp("apple", "Apple") > 0) print?
- A stair can be climbed by 1, 2 or 3 steps. How many ways are there to climb 4 stairs?
- #define N 3 and int a[N 2 + 1]; What is sizeof a / sizeof a[0]?
- int x = 5, y = 3; What does printf("%d", x & y | 4 ^ 1) print?
- unsigned int n = 3u; int k = -1; if (k > n) printf("yes"); else printf("no"); What is printed?