HomeSubjectsUniversityBlogAbout

Operators & Expressions

Topic in Programming

210 total MCQsShowing 30 with explanations10 Easy10 Medium10 Hard

About This Topic

Operators are symbols that perform computations on operands, and an expression combines operators, operands and function calls into a value. Questions test arithmetic operators including modulus for even or odd checks, relational operators like == and !=, and logical AND, OR and NOT with short-circuit evaluation. Bitwise operators (&, |, ^, ~) and shifts, including Java's unsigned right shift >>> and the difference between shifting and rotation, appear regularly. You should know operator precedence and associativity, pre- versus post-increment, the ternary and comma operators, compound assignment, the three-way comparison or spaceship operator <=>, and pitfalls of operator overloading in C++.

Below are 30 practice questions from a pool of 210 Operators & Expressions MCQs, one of 16 topics in Programming. Each shows the correct answer with an explanation; when you are ready, take a timed quiz to test recall under exam conditions.

Practice Questions

Each question below shows the correct answer with a full explanation. Use these to build conceptual understanding before attempting a timed quiz.

Operators & ExpressionsEasy

Q1. What does the + operator do with two integers?

  1. A.Concatenates them together
  2. B.Compares their values
  3. C.Multiplies them together
  4. D.Adds them arithmetically✓ Correct

Explanation

The + operator performs arithmetic addition when used with integer operands.

Report an error in this question

Operators & ExpressionsEasy

Q2. What is the result of 10 % 3?

  1. A.10
  2. B.0
  3. C.3
  4. D.1✓ Correct

Explanation

The modulus operator % returns the remainder of division: 10 divided by 3 leaves a remainder of 1.

Report an error in this question

Operators & ExpressionsEasy

Q3. Which operator is used for assignment in most programming languages?

  1. A.:=
  2. B.!=
  3. C.=✓ Correct
  4. D.==

Explanation

The single equals sign (=) is the assignment operator in most languages like C, Java, and Python.

Report an error in this question

Operators & ExpressionsEasy

Q4. What does the == operator do?

  1. A.Declares a new variable in scope
  2. B.Assigns a value to a variable
  3. C.Performs addition of two values
  4. D.Checks if two values are equal✓ Correct

Explanation

The == operator compares two values and returns true if they are equal.

Report an error in this question

Operators & ExpressionsEasy

Q5. What is the result of 5 > 3?

  1. A.true✓ Correct
  2. B.3
  3. C.false
  4. D.5

Explanation

The expression 5 > 3 evaluates to true because 5 is greater than 3.

Report an error in this question

Operators & ExpressionsEasy

Q6. Which operator performs integer division in Python 3?

  1. A.//✓ Correct
  2. B.%
  3. C.**
  4. D./

Explanation

In Python 3, the // operator performs floor (integer) division, discarding the decimal part.

Report an error in this question

Operators & ExpressionsEasy

Q7. What does the NOT (!) operator do?

  1. A.Reverses a boolean value✓ Correct
  2. B.Adds two values together
  3. C.Multiplies two operands
  4. D.Assigns a new value

Explanation

The NOT operator (!) reverses a boolean value: true becomes false and vice versa.

Report an error in this question

Operators & ExpressionsEasy

Q8. What is the result of true AND false?

  1. A.false✓ Correct
  2. B.error
  3. C.true
  4. D.null

Explanation

Logical AND returns true only when both operands are true; since one is false, the result is false.

Report an error in this question

Operators & ExpressionsEasy

Q9. What does the ++ operator do?

  1. A.Adds two variables
  2. B.Doubles the value
  3. C.Increments the value by 1✓ Correct
  4. D.Concatenates strings

Explanation

The ++ operator (increment) increases the value of a variable by 1.

Report an error in this question

Operators & ExpressionsEasy

Q10. Which operator is used for string concatenation in Java?

  1. A.+✓ Correct
  2. B.&
  3. C..
  4. D.,

Explanation

In Java, the + operator is overloaded to concatenate strings.

Report an error in this question

Operators & ExpressionsMedium

Q11. What is the difference between ++i and i++?

  1. A.++i always executes faster than i++ does overall
  2. B.++i increments before use; i++ increments after✓ Correct
  3. C.There is no difference between them at all
  4. D.i++ increments the value by two instead of one

Explanation

++i (pre-increment) increments the value before it is used in the expression; i++ (post-increment) uses the value first, then increments.

Report an error in this question

Operators & ExpressionsMedium

Q12. What is short-circuit evaluation?

  1. A.Stopping evaluation once result is known✓ Correct
  2. B.A hardware feature of modern processors
  3. C.Evaluating all conditions in every case
  4. D.A compiler optimization for loop bodies

Explanation

Short-circuit evaluation stops evaluating a logical expression as soon as the final result can be determined (e.g., false AND x skips x).

Report an error in this question

Operators & ExpressionsMedium

Q13. What is the ternary operator?

  1. A.An operator that takes a single operand only
  2. B.A conditional operator with three operands✓ Correct
  3. C.A bitwise operator for binary manipulation
  4. D.An operator that takes exactly two operands

Explanation

The ternary operator (? :) takes three operands: a condition, a value if true, and a value if false.

Report an error in this question

Operators & ExpressionsMedium

Q14. What does the << operator do in C/Java?

  1. A.Reads input from the console
  2. B.Performs a left bitwise shift✓ Correct
  3. C.Compares two values for equality
  4. D.Performs string stream insertion

Explanation

The << operator shifts the bits of a number to the left by a specified number of positions, effectively multiplying by powers of 2.

Report an error in this question

Operators & ExpressionsMedium

Q15. What is operator precedence?

  1. A.The order in which operators are defined in code
  2. B.The rules determining operator evaluation order✓ Correct
  3. C.The execution speed of a particular operator
  4. D.The data type returned by a given operator

Explanation

Operator precedence defines the order in which different operators are evaluated, e.g., * before +.

Report an error in this question

Operators & ExpressionsMedium

Q16. What is the result of 5 & 3 (bitwise AND)?

  1. A.5
  2. B.15
  3. C.8
  4. D.1✓ Correct

Explanation

5 in binary is 101, 3 is 011. Bitwise AND: 101 & 011 = 001, which is 1.

Report an error in this question

Operators & ExpressionsMedium

Q17. What is the difference between == and === in JavaScript?

  1. A.There is no difference between them
  2. B.== checks value; === checks value and type✓ Correct
  3. C.=== is used for variable assignment
  4. D.== checks type without value comparison

Explanation

== performs type coercion before comparison, while === (strict equality) checks both value and type without coercion.

Report an error in this question

Operators & ExpressionsMedium

Q18. What does the XOR (^) operator return?

  1. A.True when the operands are different✓ Correct
  2. B.Always false regardless of the operands
  3. C.True when both operands are the same
  4. D.Always true regardless of the operands

Explanation

XOR returns true when exactly one of the operands is true (i.e., when they differ).

Report an error in this question

Operators & ExpressionsMedium

Q19. What is the null coalescing operator (??) in JavaScript?

  1. A.It checks the code for syntax errors at compile time
  2. B.It returns the right operand if the left is null✓ Correct
  3. C.It always returns a null value to the caller
  4. D.It performs integer division on two operands

Explanation

The ?? operator returns the right-hand operand when the left-hand operand is null or undefined, otherwise returns the left-hand operand.

Report an error in this question

Operators & ExpressionsMedium

Q20. What is operator associativity?

  1. A.How operators are stored internally within the memory
  2. B.The direction operators of same precedence are evaluated✓ Correct
  3. C.The underlying data type of an operator in the language
  4. D.The execution speed of evaluating a given expression

Explanation

Associativity determines the evaluation direction for operators of equal precedence, e.g., assignment is right-to-left, addition is left-to-right.

Report an error in this question

Operators & ExpressionsHard

Q21. What is operator overloading?

  1. A.Defining custom behavior for user-defined types✓ Correct
  2. B.An error caused by incorrect operator usage
  3. C.Increasing the default operator precedence level
  4. D.Using too many operators in one expression

Explanation

Operator overloading allows programmers to redefine the behavior of operators for custom types, e.g., defining + for a Complex number class.

Report an error in this question

Operators & ExpressionsHard

Q22. What is the result of ~5 in a system using 32-bit signed integers?

  1. A.5
  2. B.-5
  3. C.6
  4. D.-6✓ Correct

Explanation

The bitwise NOT (~) inverts all bits. For 32-bit signed int, ~5 gives -6 because ~n = -(n+1) in two's complement representation.

Report an error in this question

Operators & ExpressionsHard

Q23. What is the spaceship operator (<=>)?

  1. A.An assignment operator for setting variables
  2. B.A comparison operator returning -1, 0, or 1✓ Correct
  3. C.A bitwise shift operator for binary values
  4. D.A logical operator for boolean expressions

Explanation

The spaceship operator (<=>) performs a three-way comparison, returning negative, zero, or positive based on the ordering of operands.

Report an error in this question

Operators & ExpressionsHard

Q24. What is the difference between arithmetic right shift (>>) and logical right shift (>>>)?

  1. A.There is no difference between them at all
  2. B.>>> preserves the sign bit; >> fills with zeros
  3. C.>> preserves the sign bit; >>> fills with zeros✓ Correct
  4. D.>> always fills the vacant bit positions with zeros

Explanation

Arithmetic right shift (>>) preserves the sign bit for signed numbers, while logical right shift (>>>) always fills vacant bits with zeros.

Report an error in this question

Operators & ExpressionsHard

Q25. What is the Elvis operator (?:) in Kotlin?

  1. A.Returns left if non-null, otherwise right✓ Correct
  2. B.A type-checking operator for null safety
  3. C.A standard ternary conditional operator
  4. D.A bitwise operator for binary operations

Explanation

The Elvis operator (?:) in Kotlin returns the left expression if it is non-null, otherwise evaluates and returns the right expression.

Report an error in this question

Operators & ExpressionsHard

Q26. How does Python's 'is' operator differ from '=='?

  1. A.is runs faster but produces less accurate results
  2. B.is checks identity; == checks value equality✓ Correct
  3. C.They are functionally identical in all cases
  4. D.== checks identity while is checks equality

Explanation

'is' checks if two references point to the same object in memory (identity), while '==' checks if the values are equal (equality).

Report an error in this question

Operators & ExpressionsHard

Q27. What is the safe navigation operator (?.) in Kotlin/TypeScript?

  1. A.It forces a null pointer exception to be thrown immediately
  2. B.It converts any null value to the integer zero automatically
  3. C.It always returns a null value regardless of the receiver
  4. D.It accesses a member only if the receiver is non-null✓ Correct

Explanation

The safe navigation (optional chaining) operator returns null if the receiver is null instead of throwing a NullPointerException.

Report an error in this question

Operators & ExpressionsHard

Q28. What does the >>> operator do in Java that >> does not?

  1. A.It fills leftmost bits with 0, ignoring the sign✓ Correct
  2. B.It operates more slowly than the >> operator
  3. C.It works on floating-point numbers unlike >>
  4. D.Nothing different from the >> operator at all

Explanation

>>> (unsigned right shift) always fills the highest bits with zeros, while >> (signed right shift) fills with the sign bit, preserving negative values.

Report an error in this question

Operators & ExpressionsHard

Q29. What is destructuring assignment?

  1. A.A type of memory deallocation for objects
  2. B.Deleting variables from the current scope
  3. C.Unpacking values from arrays or objects into variables✓ Correct
  4. D.Assigning null to multiple variables at once

Explanation

Destructuring assignment allows extracting values from arrays or objects into separate variables in a concise syntax.

Report an error in this question

Operators & ExpressionsHard

Q30. What is the pipeline operator (|>) proposed for JavaScript?

  1. A.A bitwise OR operation on binary values
  2. B.A comparison operator for ordering two values
  3. C.It passes left result as argument to right function✓ Correct
  4. D.A type conversion operator between data types

Explanation

The pipeline operator passes the value on the left as the first argument to the function on the right, enabling readable function chaining.

Report an error in this question

Ready to test yourself on Operators & Expressions?

Take a timed quiz drawn from 210+ questions on this topic. No signup required — your progress saves in your browser.

Start Operators & Expressions Quiz