All mock tests are FREE till 31 December — register to save your progress

Which of the following would be the value of z for the C program code?
x = 16;
y = 4;
z = x >> y;

Pick an option to check yourself, or open the answer below.

Show answer & explanation

Correct answer: D. 1

Explanation

The >> operator is the right-shift operator; x >> y shifts the bits of x to the right by y positions, which for a non-negative x is equivalent to integer division of x by 2^y. Here x = 16 (binary 10000) and y = 4, so z = 16 >> 4 = 16 / 2⁴ = 16 / 16 = 1. So z evaluates to 1.

More Programming Languages and Computer Graphics questions