Important Introduction to Programming Short Questions
Chapter: 31
Question 1:
Which operators can be overloaded?
Answer:
Operators that can be overloaded include +, -, *, /, %, ^, &,
Chapter: 31
Question 2:
Which operators cannot be overloaded?
Answer:
Operators that cannot be overloaded include ., :, ::, .* ?, and sizeof.
Chapter: 31
Question 3:
What are unary operators?
Answer:
Unary operators require only one operand and are applied to the left of the operand. Examples include ^, &, ~, and !.
Chapter: 31
Question 4:
What are binary operators?
Answer:
Binary operators require two operands, one on each side of the operator. Examples include +, -, *, /, %, =, <, and >.
Chapter: 31
Question 5:
Where is operator overloading relevant?
Answer:
Operator overloading is relevant in mathematical manipulations with classes (e.g., complex numbers) and non-mathematical manipulations (e.g., string concatenation).
Chapter: 31
Question 6:
What is the restriction on the arity of overloaded operators?
Answer:
The arity of an operator cannot be changed. For example, a binary operator cannot be used as a unary operator.
Chapter: 31
Question 7:
Can new operators be created in C++ through overloading?
Answer:
No, new operators cannot be created. Only existing C++ operators can be overloaded.
Chapter: 31
Question 8:
What is the purpose of a member operator function?
Answer:
A member operator function operates on the object to the left of the operator and can access its private members directly.
Chapter: 31
Question 9:
What is the syntax for a member operator function?
Answer:
The syntax is: return-type operator operator-symbol (parameter-list); For example, Complex operator + (Complex & c);
Chapter: 31
Question 10:
How does an operator function defined as a friend differ from a member operator?
Answer:
A friend operator function can access the private members of the class but is not a member function. It is used when the left operand is not an instance of the class.