Difficulty: Easy
Correct Answer: area = 5
Explanation:
Introduction / Context:
A common beginner error in C and C++ is confusing the assignment operator with the equality comparison operator. Clear understanding of operator spelling and semantics prevents logic bugs and compilation failures. This question focuses on the exact syntax required to store a literal value into a variable.
Given Data / Assumptions:
Concept / Approach:
The assignment operator in C++ is a single equals sign: =. It places the value on the right-hand side into the variable on the left-hand side. The equality comparison operator is a double equals: ==, which produces a Boolean result and does not assign. Other sequences shown in the options are not valid C++ operators for assignment and will not compile in this context.
Step-by-Step Solution:
Choose the assignment operator: =.Write the target variable first, then the operator, then the literal value.Form the statement: area = 5;Terminate with a semicolon in actual code to complete the statement.
Verification / Alternative check:
Compile a snippet with area = 5; and then print area to verify that the value has been stored. Replace = with == and observe the compiler either accept a meaningless comparison expression or produce warnings, depending on context, but it will not assign to area.
Why Other Options Are Wrong:
Common Pitfalls:
Using == inside an if condition when you meant to assign, or using = in conditions when you meant to compare. Many compilers can warn about suspicious use of = inside conditionals; enable warnings.
Final Answer:
area = 5.
Discussion & Comments