Introduction to Programming MCQs with Answers
Practice important Introduction to Programming MCQs with answers and explanations.
Chapter: 30
Q501:
Which operator is used for declaring a reference?
A. &
B. *
C. +
D. =
Correct Answer:
A
Chapter: 30
Q502:
When you declare int &j = i;, what does j represent?
A. A new integer variable
B. A reference to i
C. An address of i
D. A pointer to i
Correct Answer:
B
Chapter: 30
Q503:
What happens when you increment i if j is a reference to i?
A. Only i is incremented
B. Both i and j are incremented
C. Only j is incremented
D. i and j become different values
Correct Answer:
B
Chapter: 30
Q504:
How can you swap two integers using a reference?
A. By passing their addresses to a function
B. By using call by reference in a function
C. By using call by value in a function
D. By using pointers in a function
Correct Answer:
B
Chapter: 30
Q505:
Why is call by reference preferred over call by value for large data structures?
A. It avoids copying large data structures
B. It uses more memory
C. It is less efficient
D. It is easier to read the code
Correct Answer:
A
Chapter: 30
Q506:
What does const keyword do when used with references?
A. Prevents changes to the referenced value
B. Allows changes to the referenced value
C. Makes the reference uninitialized
D. Forces initialization of the reference
Correct Answer:
A
Chapter: 30
Q507:
Which of the following is a danger of returning a reference from a function?
A. Dangling reference
B. Memory leak
C. Null pointer exception
D. Undefined behavior
Correct Answer:
A
Chapter: 30
Q508:
How can you prevent a dangling reference?
A. Return a reference to a global or static variable
B. Use a pointer instead
C. Return by value
D. Avoid returning references
Correct Answer:
A
Chapter: 30
Q509:
What is the correct syntax for a function that returns a reference?
A. datatype& function_name()
B. datatype function_name()
C. datatype function_name&()
D. datatype function_name&
Correct Answer:
A
Chapter: 30
Q510:
Can you overload functions with similar names but different parameter types involving references?
A. Yes, if their parameter types are different
B. No, because the calls are ambiguous
C. Yes, if they are in different namespaces
D. No, because references cannot be overloaded
Correct Answer:
B
Chapter: 31
Q511:
What does operator overloading allow?
A. Same operator for multiple implementations
B. New operators to be created
C. Changing operator precedence
D. Changing operator associativity
Correct Answer:
A
Chapter: 31
Q512:
Why is operator overloading useful?
A. To make code more readable
B. To increase the number of available operators
C. To decrease execution time
D. To change the arity of operators
Correct Answer:
A
Chapter: 31
Q513:
Which of the following operators is automatically overloaded for primitive types in C++?
A. +
B. ::
C. sizeof
D. ?
Correct Answer:
A
Chapter: 31
Q514:
What type of operators can be overloaded?
A. Unary and Binary
B. Only Unary
C. Only Binary
D. None
Correct Answer:
A
Chapter: 31
Q515:
Which operator cannot be overloaded?
A. sizeof
B. +
C. -
D. /
Correct Answer:
A
Chapter: 31
Q516:
Which of the following is an example of a unary operator?
A. ++
B. +
C. -
D. /
Correct Answer:
A
Chapter: 31
Q517:
Can operator overloading change the precedence of operators?
A. No
B. Yes
C. Only for binary operators
D. Only for unary operators
Correct Answer:
A
Chapter: 31
Q518:
What must be true about the arity of overloaded operators?
A. It cannot be changed
B. It can be increased
C. It can be decreased
D. It must be the same as in built-in types
Correct Answer:
A
Chapter: 31
Q519:
In the context of operator overloading, what does the 'friend' keyword do?
A. Allows a non-member function to access private members
B. Creates a new operator
C. Overloads operators for primitive types
D. Changes operator precedence
Correct Answer:
A
Chapter: 31
Q520:
What is the benefit of using member operator functions?
A. The left operand drives the operation
B. The right operand drives the operation
C. Both operands are equal
D. None
Correct Answer:
A