IGDTUW 2026 Computer PYQ — What is the output of the following C++ code? #include <iostream>… | Mathem Solvex | Mathem Solvex
Tip:A–D to answerE for explanationV for videoS to reveal answer
IGDTUW 2026 — Computer PYQ
IGDTUW | Computer | 2026
What is the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
int x = 20;
cout << (x >> 2);
return 0;
}
Choose the correct answer:
A.
2
B.
4
C.
5
(Correct Answer)
D.
10
Correct Answer:
5
Explanation
The correct option is (c) 5.
Step-by-Step Explanation:
Understanding the Right Shift Operator (>>):
The >> operator is the bitwise right shift operator. It shifts the bits of the left operand to the right by the number of positions specified by the right operand.
Mathematical Shortcut:
Shifting an integer right by n positions is mathematically equivalent to integer division by 2n:
Result=⌊2nx⌋
Calculation:
Given x=20 and n=2:
Result=⌊2220⌋=⌊420⌋=5
Bitwise Representation:
The 8-bit binary representation of 20 is:
000101002
Shifting the bits to the right by 2 positions drops the lowest two bits and fills the leftmost bits with zeros:
000001012
Converting the resulting binary number 000001012 back to decimal yields:
(1×22)+(0×21)+(1×20)=4+0+1=5
Therefore, the program outputs:
5
Explanation
The correct option is (c) 5.
Step-by-Step Explanation:
Understanding the Right Shift Operator (>>):
The >> operator is the bitwise right shift operator. It shifts the bits of the left operand to the right by the number of positions specified by the right operand.
Mathematical Shortcut:
Shifting an integer right by n positions is mathematically equivalent to integer division by 2n:
Result=⌊2nx⌋
Calculation:
Given x=20 and n=2:
Result=⌊2220⌋=⌊420⌋=5
Bitwise Representation:
The 8-bit binary representation of 20 is:
000101002
Shifting the bits to the right by 2 positions drops the lowest two bits and fills the leftmost bits with zeros:
000001012
Converting the resulting binary number 000001012 back to decimal yields: