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 a = 7;
cout << (a & 1);
return 0;
}
Choose the correct answer:
A.
0
B.
1
C.
7
(Correct Answer)
D.
Compilation Error
Correct Answer:
7
Explanation
Step-by-Step Explanation:
Variable Initialization: An integer variable a is declared and initialized with the value 7.
int a=7;
Understanding the Bitwise AND Operator (&): The expression (a & 1) uses the bitwise AND operator. This operator compares corresponding bits of two values and results in 1 if both bits are 1, and 0 otherwise.
Binary Evaluation: To evaluate the operation, convert the decimal integers to their binary equivalents:
7 in binary: 000001112
1 in binary: 000000012
Aligning the bits for the bitwise operation gives:
000001112 & 000000012000000012(7)(1)(1)
The resulting binary sequence evaluates to the decimal value:
1
Key Logic Insight: Using number & 1 isolates the least significant bit (LSB) of an integer. Because odd numbers always end with a binary 1 at the LSB position, performing a bitwise AND with 1 will always return 1 for odd numbers and 0 for even numbers. Since 7 is an odd integer, the output is guaranteed to be 1.
Therefore, the program outputs:
1
Explanation
Step-by-Step Explanation:
Variable Initialization: An integer variable a is declared and initialized with the value 7.
int a=7;
Understanding the Bitwise AND Operator (&): The expression (a & 1) uses the bitwise AND operator. This operator compares corresponding bits of two values and results in 1 if both bits are 1, and 0 otherwise.
Binary Evaluation: To evaluate the operation, convert the decimal integers to their binary equivalents:
7 in binary: 000001112
1 in binary: 000000012
Aligning the bits for the bitwise operation gives:
000001112 & 000000012000000012(7)(1)(1)
The resulting binary sequence evaluates to the decimal value:
1
Key Logic Insight: Using number & 1 isolates the least significant bit (LSB) of an integer. Because odd numbers always end with a binary 1 at the LSB position, performing a bitwise AND with 1 will always return 1 for odd numbers and 0 for even numbers. Since 7 is an odd integer, the output is guaranteed to be 1.