Operators in C ++ Programming MCQ Questions and Answers
1. Which of the following operators cannot be overloaded in C++?
A) +
B) []
C) ::
D) ()
Answer: C) ::
2. What is the associativity of the assignment operator (=) in C++?
A) Left to Right
B) Right to Left
C) Top to Bottom
D) Undefined
Answer: B) Right to Left
3. The sizeof operator in C++ is evaluated at:
A) Compile time
B) Run time
C) Both compile and run time
D) Link time
Answer: A) Compile time
4. Which operator has the highest precedence in C++?
A) ++ (postfix)
B) * (multiplication)
C) = (assignment)
D) && (logical AND)
Answer: A) ++ (postfix)
5. Which operator is used to allocate memory dynamically in C++?
A) malloc
B) new
C) calloc
D) sizeof
Answer: B) new
6. Which of the following operators cannot be overloaded as a friend function?
A) +
B) ==
C) =
D) <<
Answer: C) =
7. The conditional operator ?: requires how many operands?
A) One
B) Two
C) Three
D) Four
Answer: C) Three
8. In C++, which operator is used to access a member through a pointer to an object?
A) .
B) ->
C) *
D) &
Answer: B) ->
9. The expression a += b is equivalent to:
A) a = a + b
B) a = b + b
C) a = b + a
D) a = a – b
Answer: A) a = a + b
10. What is the result of 10 / 4 in C++ when both operands are integers?
A) 2.5
B) 2
C) 2.0
D) 3
Answer: B) 2
11. In operator overloading, which operator must be a member function if overloaded?
A) []
B) +
C) ==
D) <
Answer: A) []
12. The typeid operator in C++ is used for:
A) Type casting
B) Type identification
C) Memory allocation
D) Object destruction
Answer: B) Type identification
13. Which operator is used to free memory allocated by new?
A) free()
B) delete
C) dispose
D) destroy
Answer: B) delete
14. What is the output of the following code?
int a = 5;
cout << ++a * 2;
A) 10
B) 12
C) 11
D) 14
Answer: B) 12
15. Which of the following operators has the lowest precedence?
A) ++
B) *
C) =
D) %
Answer: C) =
16. Which operator is used to access a class’s static member?
A) .
B) ->
C) ::
D) &
Answer: C) ::
17. What will be the output of the code?
int a = 3, b = 2;
cout << a % b;
A) 0
B) 1
C) 2
D) 3
Answer: B) 1
18. Which operator returns the address of a variable?
A) *
B) &
C) ->
D) %
Answer: B) &
19. In C++, which of the following statements is true about operator overloading?
A) You can create new operators.
B) You can change operator precedence.
C) You can overload existing operators.
D) None of the above.
Answer: C) You can overload existing operators.
20. What will be the output of this code?
int a = 4, b = 3;
cout << a++ + ++b;
A) 7
B) 8
C) 9
D) 10
Answer: C) 9
21. The dynamic_cast operator is mainly used for:
A) Arithmetic operations
B) Explicit type conversion in inheritance
C) Logical comparison
D) Static conversion
Answer: B) Explicit type conversion in inheritance
22. Which operator cannot be used with pointers in C++?
A) ++
B) —
C) *
D) %
Answer: D) %
23. The comma operator (,) in C++:
A) Has the lowest precedence
B) Has the highest precedence
C) Evaluates all operands from right to left
D) Is not supported
Answer: A) Has the lowest precedence
24. What is the output of the following code?
int x = 10;
cout << (x == 10 ? 5 : 0);
A) 0
B) 5
C) 10
D) Error
Answer: B) 5
25. Which operator is used to dereference a pointer?
A) &
B) *
C) ->
D) ::
Answer: B) *
26. Which operator can be used to test two conditions simultaneously in C++?
A) ||
B) &&
C) &
D) |
Answer: B) &&
27. Which of the following is a unary operator?
A) +
B) –
C) sizeof
D) &&
Answer: C) sizeof
28. The expression *ptr++ is equivalent to:
A) (*ptr)++
B) *(ptr++)
C) ++(*ptr)
D) ++ptr*
Answer: B) *(ptr++)
29. In C++, which operator has higher precedence among the following?
A) &&
B) ==
C) +
D) *
Answer: D) *
30. Which operator can be overloaded only as a member function?
A) ->
B) +
C) ==
D) <<
Answer: A) ->
31. What is the result of the following expression?
int x = 5;
int y = x++ + ++x;
A) 11
B) 12
C) 10
D) Undefined behavior
Answer: D) Undefined behavior
32. The expression a && b || c is evaluated as:
A) (a && b) || c
B) a && (b || c)
C) a || (b && c)
D) None of these
Answer: A) (a && b) || c
33. What is the output of the following code?
int x = 7, y = 2;
cout << x / y * y;
A) 7
B) 6
C) 8
D) 2
Answer: B) 6
34. Which of the following cannot be overloaded in C++?
A) ==
B) ->
C) ?:
D) +
Answer: C) ?:
35. What is the meaning of ::x inside a member function?
A) Refers to the current object’s variable
B) Refers to global variable x
C) Refers to local variable x
D) Causes ambiguity
Answer: B) Refers to global variable x
36. Which of the following correctly declares an overloaded + operator as a member function?
A) int operator+(int a, int b);
B) int operator+(int b);
C) friend int operator+(int a, int b);
D) void operator+();
Answer: B) int operator+(int b);
37. What will be the output of this code?
int a = 3, b = 4;
cout << (a & b);
A) 0
B) 7
C) 1
D) 0
Answer: C) 0b011 & 0b100 = 0b000 = 0
Correct choice: A) 0
38. Which operator is used for object-to-object assignment?
A) =
B) ==
C) ->
D) ::
Answer: A) =
39. In operator overloading, which of the following is true?
A) It changes the meaning of operators permanently
B) It changes meaning only for user-defined types
C) It modifies built-in behavior globally
D) It cannot be used with classes
Answer: B) It changes meaning only for user-defined types
40. Which operator is automatically called when an object goes out of scope?
A) ->
B) =
C) ~
D) delete
Answer: C) ~
41. What is the output of the following code?
int x = 2, y = 3;
cout << (x | y);
A) 0
B) 2
C) 3
D) 7
Answer: D) 7
42. Which of the following operators can be overloaded for a class in C++?
A) sizeof
B) .
C) ::
D) []
Answer: D) []
43. The operator -> is a combination of which two operators?
A) * and .
B) & and *
C) * and ->
D) . and ::
Answer: A) * and .
44. What is the output of the following code?
int a = 10;
cout << (a >> 1);
A) 20
B) 5
C) 0
D) 15
Answer: B) 5
45. The explicit keyword in C++ is related to which operator concept?
A) Type casting
B) Function overloading
C) Operator overloading
D) Scope resolution
Answer: C) Operator overloading
46. The ! operator in C++ is used for:
A) Bitwise inversion
B) Logical NOT
C) Addressing
D) Dereferencing
Answer: B) Logical NOT
47. What is the output of this code?
int a = 1, b = 2, c = 3;
cout << (a < b < c);
A) 0
B) 1
C) True
D) Error
Answer: B) 1
48. What will cout << (10, 20); print?
A) 10
B) 20
C) 30
D) Error
Answer: B) 20
49. What is the output of this code?
int x = 5;
cout << (x++, ++x);
A) 5 6
B) 6 7
C) Undefined behavior
D) Error
Answer: C) Undefined behavior
50. Which operator is used to specify namespaces in C++?
A) ->
B) .
C) ::
D) #
Answer: C) ::
51. Which of the following operators cannot be overloaded for built-in data types?
A) +
B) –
C) =
D) None of these
Answer: D) None of these
52. What will be the output of this code?
int a = 2, b = 3;
cout << (a << b);
A) 5
B) 6
C) 16
D) 8
Answer: C) 16
53. Which operator can be used to combine two or more expressions where only the last result is returned?
A) &&
B) ||
C) ,
D) ;
Answer: C) ,
54. Which operator is used in C++ to access the address of a variable?
A) *
B) &
C) ->
D) ::
Answer: B) &
55. The output of this code will be what?
int x = 10;
x = x++ + ++x;
cout << x;
A) 22
B) Undefined behavior
C) 21
D) 20
Answer: B) Undefined behavior
56. Which of the following correctly represents an overloaded insertion operator for a class Demo?
A) ostream operator<<(Demo d);
B) ostream& operator<<(ostream&, Demo&);
C) ostream operator<<(ostream&, Demo);
D) Demo operator<<(ostream&, Demo&);
Answer: B) ostream& operator<<(ostream&, Demo&);
57. Which of the following cannot be overloaded as a member function?
A) +
B) ->
C) =
D) ()
Answer: C) =
58. Which operator is evaluated first in the expression x + y * z?
A) +
B) *
C) =
D) Both simultaneously
Answer: B) *
59. Which of the following is a bitwise operator?
A) &&
B) ||
C) !
D) &
Answer: D) &
60. Which operator can be used to overload object input using cin?
A) >>
B) <<
C) ->
D) ::
Answer: A) >>
61. What will be the result of this code?
int x = 5;
cout << (x > 2 && x < 10);
A) 0
B) 1
C) True
D) False
Answer: B) 1
62. Which of the following is the correct order of operator precedence?
A) ++, *, +, =
B) =, +, *, ++
C) *, ++, =, +
D) +, =, *, ++
*Answer: A) ++, , +, =
63. The statement a = b = c = 5; is evaluated as:
A) a = ((b = c) = 5)
B) (a = (b = (c = 5)))
C) ((a = b) = (c = 5))
D) Error
Answer: B) (a = (b = (c = 5)))
64. What is the output of this code?
int a = 4;
cout << (a == 4 ? 10 : 20);
A) 4
B) 10
C) 20
D) 0
Answer: B) 10
65. Which of the following statements is true regarding operator overloading?
A) It changes the number of operands of an operator
B) It allows defining new operators
C) It redefines existing operators for user-defined types
D) It allows altering operator precedence
Answer: C) It redefines existing operators for user-defined types
66. Which operator function must be defined as a member function?
A) =
B) <<
C) +
D) *
Answer: A) =
67. Which operator in C++ performs bitwise exclusive OR?
A) |
B) ^
C) &
D) ~
Answer: B) ^
68. The this pointer is implicitly passed to which type of operator overload?
A) Global operator functions
B) Member operator functions
C) Friend operator functions
D) Static functions
Answer: B) Member operator functions
69. The operator sizeof returns which type of value?
A) int
B) float
C) size_t
D) double
Answer: C) size_t
70. Which of the following expressions is invalid in C++?
A) int x = 5; x++;
B) int y = ++5;
C) int z = 5 + 2;
D) int a = 10 – 5;
Answer: B) int y = ++5;
71. Which operator cannot be overloaded to work on user-defined types directly?
A) +
B) =
C) .*
D) <<
Answer: C) .
72. The precedence of relational operators (<, >, <=, >=) is:
A) Higher than arithmetic operators
B) Lower than arithmetic operators
C) Equal to assignment operators
D) Same as logical operators
Answer: B) Lower than arithmetic operators
73. What will be the result of this expression?
int a = 3, b = 5;
cout << (a & b) << endl;
A) 1
B) 5
C) 7
D) 15
Answer: A) 1
74. What is the output of this code?
int x = 10;
cout << (x += 5);
A) 5
B) 10
C) 15
D) 20
Answer: C) 15
75. Which operator is used to access class members through objects?
A) ::
B) ->
C) .
D) #
Answer: C) .
76. Which of the following operators has the lowest precedence in C++?
A) +
B) &&
C) =
D) ||
Answer: C) =
77. What will be the output of this code?
int a = 2, b = 3;
cout << (a * b + b / a);
A) 7
B) 8
C) 6
D) 5
Answer: A) 7
78. Which operator can be used to check memory allocation success when using new in C++?
A) ==
B) ?
C) nullptr check
D) sizeof
Answer: C) nullptr check
79. What is the associativity of the ternary operator ?: in C++?
A) Left to Right
B) Right to Left
C) Top to Bottom
D) Undefined
Answer: B) Right to Left
80. What is the output of the code?
int a = 5;
cout << (++a) * (a++);
A) 30
B) 35
C) 25
D) Undefined behavior
Answer: D) Undefined behavior
81. The operator typeid is defined in which C++ header file?
A) <typeinfo>
B) <ttypeinfo>
C) <stdlib.h>
D) <types.h>
Answer: A)
82. Which operator is called when we copy one object to another at declaration time?
A) Assignment operator (=)
B) Copy constructor
C) Move constructor
D) Initialization operator
Answer: B) Copy constructor
83. What will the following code print?
int a = 10, b = 20;
cout << !(a > b);
A) 0
B) 1
C) True
D) False
Answer: B) 1
84. Which of the following is a unary arithmetic operator in C++?
A) *
B) ++
C) +
D) /
Answer: B) ++
85. Which operator can be overloaded to create user-defined conversions?
A) operator()
B) operator[]
C) operator type()
D) operator->
Answer: C) operator type()
86. What is the output of this code?
int a = 5, b = 2;
cout << a / b * b + a % b;
A) 5
B) 6
C) 4
D) 2
Answer: A) 5
87. Which operator is used to invoke a function call?
A) ()
B) ->
C) []
D) *
Answer: A) ()
88. Which of the following is true about overloading the assignment operator (=)?
A) It must be a friend function
B) It must return a void
C) It must return a reference to the invoking object
D) It cannot be overloaded
Answer: C) It must return a reference to the invoking object
89. What will be the output of this code?
int a = 1, b = 2, c = 3;
cout << (a + b == c);
A) 0
B) 1
C) True
D) Error
Answer: B) 1
90. The operator .* is used for:
A) Accessing static members
B) Accessing pointer-to-member of object
C) Accessing base class data
D) None of these
Answer: B) Accessing pointer-to-member of object
91. Which operator can be overloaded to mimic array behavior?
A) ->
B) ()
C) []
D) ::
Answer: C) []
92. Which of the following is not a bitwise operator?
A) &
B) |
C) ^
D) &&
Answer: D) &&
93. What will be the output of the code?
int x = 5;
cout << (x << 1);
A) 10
B) 6
C) 7
D) 4
Answer: A) 10
94. What is the result of the following statement?
int a = 4, b = 6;
a ^= b;
cout << a;
A) 2
B) 4
C) 6
D) 0
Answer: A) 2
95. Which operator is automatically called when we use cout << obj; where obj is a class object?
A) operator<<()
B) operator>>()
C) operator=()
D) operator()()
Answer: A) operator<<()
96. What is the output of this code?
int x = 10;
cout << (x == 10) + (x = 5);
A) 0
B) 1
C) 6
D) Undefined behavior
Answer: C) 6
97. The sizeof operator can be applied to:
A) Variables only
B) Data types only
C) Both variables and data types
D) Objects only
Answer: C) Both variables and data types
98. What is the purpose of the scope resolution operator :: in C++?
A) To access class members
B) To resolve ambiguity between global and local identifiers
C) To define macros
D) To access private members
Answer: B) To resolve ambiguity between global and local identifiers
99. What is the output of the code?
int a = 5, b = 0;
cout << (b || a++);
cout << a;
A) 1 6
B) 1 5
C) 0 5
D) 0 6
Answer: B) 1 5
100. Which of the following is true about operator overloading in C++?
A) It can change operator precedence
B) It cannot overload all operators
C) It can introduce new operators
D) It changes compiler behavior
Answer: B) It cannot overload all operators
