Which operator is used to compare two values and returns a Boolean result, distinct from the assignment operator?

Study for the CodeHS AP Computer Science Principles (CSP) Exam. Prepare with flashcards and multiple choice questions, each question comes with hints and explanations. Get ready for success!

Multiple Choice

Which operator is used to compare two values and returns a Boolean result, distinct from the assignment operator?

Explanation:
The main idea here is distinguishing assignment from comparison. The operator that checks whether two values are equal and yields a true or false result is the equality operator. It is written as two equal signs (==) and is used in conditions to test equality, like if a == b. The single equals sign is the assignment operator, which stores a value into a variable and doesn’t produce a Boolean result, so it isn’t used for testing. The other options are also comparison operators (not equal, and less than or equal), but the one that specifically checks for equality is the correct choice.

The main idea here is distinguishing assignment from comparison. The operator that checks whether two values are equal and yields a true or false result is the equality operator. It is written as two equal signs (==) and is used in conditions to test equality, like if a == b. The single equals sign is the assignment operator, which stores a value into a variable and doesn’t produce a Boolean result, so it isn’t used for testing. The other options are also comparison operators (not equal, and less than or equal), but the one that specifically checks for equality is the correct choice.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy