Introduction to Programming MCQs with Answers
Practice important Introduction to Programming MCQs with answers and explanations.
Multiple Choice Questions
Q431: What must be done if an inline function is included in multiple source files?
- A: Only the source file with the inline function must be recompiled.
- B: All source files including the inline function must be recompiled.
- C: No recompilation is needed if the header file is included.
- D: The inline function must be moved to a separate source file.
View Answer
B
Q432: What does function overloading allow in C++?
- A: It allows multiple functions with the same name but different return types.
- B: It allows multiple functions with the same name and parameters.
- C: It allows multiple functions with the same name but different parameter types.
- D: It allows only one function with a unique name.
View Answer
C
Q433: How does the compiler differentiate between overloaded functions?
- A: By the return type of the functions.
- B: By the number of arguments and their types.
- C: By the function names only.
- D: By the order of function declarations.
View Answer
B
Q434: What is the result of calling sqrt(10.5) if sqrt is overloaded for both int and double?
- A: The int version of sqrt is called.
- B: The double version of sqrt is called.
- C: The compiler will throw an error.
- D: The result depends on the value of 10.5.
View Answer
B
Q435: Why can't return types be used to distinguish overloaded functions?
- A: Because return types are not considered when overloading functions.
- B: Because return types are always the same for overloaded functions.
- C: Because the compiler ignores return types during function resolution.
- D: Because return types are only for function declarations.
View Answer
A
Q436: What does the function stringCopy do in the provided example?
- A: It copies a string using strcpy or strncpy depending on the parameters.
- B: It concatenates two strings using strcat.
- C: It compares two strings for equality.
- D: It prints a string to the console.
View Answer
A
Q437: In the example provided, what is the result of cout << stringb << " and " << stringa;?
- A: It displays "That and This is a string".
- B: It displays "This is a string and That".
- C: It displays "This and That".
- D: It displays "That and This".
View Answer
B
Q438: What is the primary purpose of a class in object-oriented programming?
- A: To define a new data type with data and functions
- B: To perform mathematical operations
- C: To store data only
- D: To implement a control flow
View Answer
A
Q439: In the context of a class, what are 'member functions'?
- A: Functions that operate on data members
- B: Functions that only manipulate data externally
- C: Functions that are not related to the class
- D: Functions with no parameters
View Answer
A
Q440: How are objects of a class created in C++?
- A: By using the new keyword only
- B: By declaring a variable of the class type
- C: By defining a function
- D: By using the delete keyword only
View Answer
B