Introduction to Programming MCQs with Answers
Practice important Introduction to Programming MCQs with answers and explanations.
Chapter: 8
Q121:
What data types can be used in the expression of a switch statement?
A. Any data type
B. Only integers
C. Only floating-point numbers
D. Only strings
Correct Answer:
B
Chapter: 8
Q122:
How does the continue statement affect the flow of a loop?
A. It exits the loop immediately
B. It skips the remaining code in the loop and proceeds to the next iteration
C. It breaks out of the loop completely
D. It restarts the loop from the beginning
Correct Answer:
B
Chapter: 8
Q123:
When is the default case in a switch statement executed?
A. When all other cases match
B. When no other cases match
C. When the break statement is omitted
D. When the switch statement is terminated
Correct Answer:
B
Chapter: 8
Q124:
What should you do if you want multiple cases in a switch statement to execute the same block of code?
A. Use a break statement in each case
B. Combine the cases and use a single break statement
C. Remove all break statements
D. Use nested switch statements
Correct Answer:
B
Chapter: 8
Q125:
In which scenario should you use the goto statement?
A. When structured programming is desired
B. When a single point of control is needed
C. When you need to jump between different parts of the code
D. When you want to make code easy to trace and debug
Correct Answer:
C
Chapter: 8
Q126:
Which statement is correct regarding the break statement in loops?
A. It is used to terminate the loop and transfer control to the statement immediately following the loop
B. It causes the loop to execute one more time
C. It continues the loop with the next iteration
D. It skips the current iteration and jumps to the end of the loop
Correct Answer:
A
Chapter: 8
Q127:
What is the purpose of the continue statement in a loop?
A. To exit the loop
B. To skip the remaining code in the loop and proceed with the next iteration
C. To terminate the loop
D. To break out of the loop
Correct Answer:
B
Chapter: 8
Q128:
How does the switch statement handle character inputs in C?
A. Characters are treated as whole numbers based on their ASCII values
B. Characters must be converted to integers before being used
C. Characters are not supported in switch statements
D. Characters can be used only if they are uppercase
Correct Answer:
A
Chapter: 8
Q129:
What is the effect of using a default case in a switch statement?
A. It is mandatory to use it
B. It is optional and only executed if no other case matches
C. It is executed only when the break statement is omitted
D. It is used to handle complex conditions
Correct Answer:
B
Chapter: 8
Q130:
Which of the following is true about the goto statement in modern programming practices?
A. It is recommended for better code readability
B. It is used to jump to any part of the program without restrictions
C. It is discouraged because it can lead to hard-to-maintain code
D. It helps in making structured programs
Correct Answer:
C
Chapter: 8
Q131:
In the given program example, how is the salary range handled in the switch statement?
A. By using multiple cases and dividing the salary by 10,000
B. By using compound conditions in each case
C. By converting the salary to a character
D. By using floating-point values for precision
Correct Answer:
A
Chapter: 8
Q132:
What is the recommended practice for using break statements in loops?
A. Minimize their use to keep the code simple
B. Use them frequently to control the flow
C. Avoid using them to ensure all loop iterations are executed
D. Use them only in switch statements
Correct Answer:
A
Chapter: 8
Q133:
How should you handle multiple conditions with the same result in a switch statement?
A. Use separate cases for each condition and duplicate the code
B. Combine cases and place the common code block after the cases
C. Use a default case to handle all conditions
D. Use nested switch statements for each condition
Correct Answer:
B
Chapter: 9
Q134:
What is the purpose of functions in C programming?
A. To store data permanently
B. To perform a specific task
C. To define variable types
D. To initialize the program
Correct Answer:
B
Chapter: 9
Q135:
Which of the following is a valid function declaration in C?
A. int add(int, int);
B. int add(int a, b);
C. int add(a, b) int;
D. add(int a, int b) { return a + b; }
Correct Answer:
A
Chapter: 9
Q136:
How is a function called in C?
A. By defining its body
B. By using its name with arguments
C. By declaring it with a prototype
D. By assigning it to a variable
Correct Answer:
B
Chapter: 9
Q137:
What keyword is used to return a value from a function in C?
A. yield
B. exit
C. return
D. send
Correct Answer:
C
Chapter: 9
Q138:
If a function does not return a value, what should its return type be?
A. int
B. void
C. float
D. char
Correct Answer:
B
Chapter: 9
Q139:
In C, which type of function is used for testing conditions and returning true or false?
A. void
B. int
C. float
D. char
Correct Answer:
B
Chapter: 9
Q140:
What will the following code snippet return: int square(int x) { return x * x; }?
A. The value of x multiplied by x
B. The square root of x
C. The absolute value of x
D. The value of x divided by x
Correct Answer:
A