Introduction to Programming MCQs with Answers
Practice important Introduction to Programming MCQs with answers and explanations.
Multiple Choice Questions
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
View Answer
C
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
View Answer
B
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
View Answer
B
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
View Answer
C
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
View Answer
C
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
View Answer
A
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
View Answer
C
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.
View Answer
C
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.
View Answer
B
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.
View Answer
D