C++ Operators MCQ

Operators are foundational in any programming language, and C++ is no exception. They perform various operations on variables and values. Let’s test your knowledge of C++ operators with this beginner-friendly quiz!

1. Which of the following is the assignment operator in C++?

a) ==
b) =
c) ===
d) :=

Answer:

b) =

Explanation:

The = operator is used for assignment in C++. It assigns the value on its right to the variable on its left.

2. Which operator is used for checking equality?

a) :=
b) =
c) ==
d) !=

Answer:

c) ==

Explanation:

The == operator checks if the values of two operands are equal or not.

3. What is the result of 5 % 2?

a) 2.5
b) 2
c) 1
d) 0

Answer:

c) 1

Explanation:

The % operator calculates the remainder of the division. 5 divided by 2 has a remainder of 1.

4. Which operator increases the value of a variable by 1?

a) ++
b) —
c) +=
d) *=

Answer:

a) ++

Explanation:

The ++ operator is the increment operator. It increases the value of a variable by 1.

5. What is the purpose of the != operator?

a) Multiplication
b) Modulus
c) Not equal to
d) Division

Answer:

c) Not equal to

Explanation:

The != operator checks if two operands are not equal.

6. What does the && operator represent?

a) Bitwise AND
b) Logical AND
c) Bitwise OR
d) Logical OR

Answer:

b) Logical AND

Explanation:

The && operator is the logical AND operator. It returns true if both operands are true.

7. Which operator has the highest precedence?

a) +
b) /
c) %
d) ()

Answer:

d) ()

Explanation:

Parentheses () have the highest precedence in C++. Expressions inside them are evaluated first.

8. What is the result of 10 | 5?

a) 15
b) 5
c) 2
d) 10

Answer:

a) 15

Explanation:

The | operator is a bitwise OR operator. In binary, 10 is 1010 and 5 is 0101. The OR operation results in 1111 which is 15 in decimal.

9. Which operator is used to allocate dynamic memory in C++?

a) malloc
b) new
c) alloc
d) create

Answer:

b) new

Explanation:

The new operator is used in C++ to allocate dynamic memory on the heap.

10. What does the ^ operator do in C++?

a) Exponentiation
b) Logical XOR
c) Bitwise XOR
d) None of the above

Answer:

c) Bitwise XOR

Explanation:

In C++, the ^ operator is the bitwise XOR operator. It returns 1 for differing bits and 0 for identical bits.

Congratulations on completing the quiz! Understanding operators is key to mastering C++ programming. If you found this quiz challenging, consider revisiting the topic and practicing with hands-on examples. Happy coding!


Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top