GATE Computer ScienceVery hardGATE CS (PYQ pattern)
unsigned char x = 0x5B; unsigned s = 0; for (int i = 0; i < 6; i++) { x ^= (unsigned char)(x << 3); x ^= x >> 2; s += x; } printf("%u %u", s, x); What is printed?
- A. 895 175
- B. 911 236
- C. 943 80
- D. 911 175
Correct answer: D. 911 175
Each step stays within 8 bits (x << 3 is truncated by the cast, and x >> 2 only shrinks). The six successive values are [163, 149, 50, 138, 236, 175], adding to 911.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- A bracket checker pushes every opening bracket and, on a closing bracket, pops and compares. For the string {[()()]([{}])}[({[]}) the…
- A queue holds 5, 12, 7, 3, 9, 14, 2, 8 (front first). To reverse the first 5 elements, they are dequeued onto a stack, popped back and…
- In the binary tree (key, left, right) = (44, (20, (12), (8)), (24, (9, (4), (5)), (15, -, (15)))), how many non-leaf nodes have a key…
- int ds(int n) { return n < 10 ? n : ds(n / 10) + n % 10; } int steps(int n) { int c = 0; while (n >= 10) { n = ds(n); c++; } return c; }…
- The keys 3, 9, 6, 12, 1, 15, 8 are inserted one after another into an initially empty max-heap (each insertion places the key at the end…
- int fib(int n) { if (n < 2) return n; return fib(n-1) + fib(n-2); } Including the initial call, how many times is fib executed in total…