Which is the correct syntax for a basic if statement in C++?
Options
A.
if x > 0 { }
B.
if (x > 0) { }
C.
if (x > 0); { }
D.
More than one of the above
E.
None of the above
Correct Answer (Detailed Explanation is Below)
B.
if (x > 0) { }
Detailed Explanation
Correct Answer: B — if (x > 0) { }
Explanation: A C++ if statement uses parentheses around its condition. Curly braces can enclose the statements controlled by the condition. Option C has an empty if body because of the semicolon.