Important MCQ

if (x = 5) in C++

Q.if (x = 5) in C++

A) gives an error always
B) is always false
C) assigns 5 to x and is true
D) compares x with 5
Correct Answer:
Option C
Detailed Explanation:
C) assigns 5 to x and is true is correct. Relational operators compare values and return true (1) or false (0). The assignment operator = is different from the equality operator ==; zero is false and non-zero values are true in conditions.