Introduction to Programming MCQs with Answers
Practice important Introduction to Programming MCQs with answers and explanations.
Multiple Choice Questions
Q501: Which operator is used for declaring a reference?
- A: &
- B: *
- C: +
- D: =
View Answer
A
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
View Answer
B
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
View Answer
B
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
View Answer
B
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
View Answer
A
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
View Answer
A
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
View Answer
A
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
View Answer
A
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&
View Answer
A
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
View Answer
B