Introduction to Programming MCQs with Answers
Practice important Introduction to Programming MCQs with answers and explanations.
Chapter: 25
Q421:
Which of the following is a rule of structured programming?
A. Long functions should not be broken into smaller tasks
B. Functions should have multiple entry and exit points
C. Functions should have a single entry and single exit
D. Comments are unnecessary
Correct Answer:
C
Chapter: 25
Q422:
In C++, where should default function arguments be placed?
A. On the left side of the parameter list
B. On the right side of the parameter list
C. Anywhere in the parameter list
D. Before the function prototype
Correct Answer:
B
Chapter: 25
Q423:
What is the output when the function f() is called with no arguments, given the definition void f (int i = 1, double x = 10.5)?
A. i = 0, x = 0.0
B. i = 1, x = 10.5
C. i = 2, x = 10.5
D. i = 1, x = 2.0
Correct Answer:
B
Chapter: 25
Q424:
Which scientist is credited with enhancing the C language to create C++?
A. Dennis Ritchie
B. Ken Thompson
C. Bejarne Stroustrup
D. James Gosling
Correct Answer:
C
Chapter: 25
Q425:
What does the inline keyword in C++ indicate?
A. The function should not be compiled
B. The function should be ignored by the compiler
C. The function's definition should be inserted wherever it is called
D. The function should be treated as a macro
Correct Answer:
C
Chapter: 25
Q426:
What is a disadvantage of using inline functions in C++?
A. It increases the size of the program
B. It slows down the program
C. It prevents the use of macros
D. It makes the code unreadable
Correct Answer:
A
Chapter: 25
Q427:
In C++, when are variable declarations most readable?
A. At the start of the program
B. At the top of the function
C. Just before they are used
D. Outside the code block
Correct Answer:
C
Chapter: 25
Q428:
What is the primary difference between inline functions and macros?
A. Inline functions can have side effects, while macros do not.
B. Macros perform type checking, while inline functions do not.
C. Macros are replaced by values directly, while inline functions are not.
D. Inline functions are expanded inline, while macros are not.
Correct Answer:
C
Chapter: 25
Q429:
How does the macro MAX in the example code cause unexpected behavior?
A. It performs type checking, which affects the output.
B. It increments variables twice due to repeated parameter usage.
C. It correctly increments variables only once.
D. It does not have side effects on variables.
Correct Answer:
B
Chapter: 25
Q430:
Why is the inline function max preferred over the macro MAX in the example?
A. It performs type checking and does not cause side effects.
B. It increments variables twice, causing incorrect results.
C. It cannot be used in multiple source files.
D. It has no side effects and provides correct results.
Correct Answer:
D
Chapter: 25
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.
Correct Answer:
B
Chapter: 25
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.
Correct Answer:
C
Chapter: 25
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.
Correct Answer:
B
Chapter: 25
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.
Correct Answer:
B
Chapter: 25
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.
Correct Answer:
A
Chapter: 25
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.
Correct Answer:
A
Chapter: 25
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".
Correct Answer:
B
Chapter: 26
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
Correct Answer:
A
Chapter: 26
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
Correct Answer:
A
Chapter: 26
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
Correct Answer:
B