Important Introduction to Programming Short Questions
Chapter: 8
Question 1:
What happens if no case in a switch statement matches the expression's value?
Answer:
If no case matches, the statements in the optional default block are executed, if it is provided; otherwise, nothing happens.
Chapter: 8
Question 2:
How does the use of break statements affect the execution of a switch statement?
Answer:
Break statements terminate the execution of the current case, preventing the execution of subsequent cases, which would otherwise continue sequentially.
Chapter: 8
Question 3:
What is the significance of using both upper and lower case characters in switch cases?
Answer:
Using both upper and lower case characters allows the program to handle input more flexibly, accepting both 'A' and 'a' for the same case, for example.
Chapter: 8
Question 4:
What is the role of the continue statement in a loop?
Answer:
The continue statement skips the remaining statements in the loop's current iteration and forces the next iteration of the loop to begin immediately.
Chapter: 8
Question 5:
How does the use of continue differ between while and for loops?
Answer:
In a while loop, the continue statement forces the next iteration by reevaluating the condition, while in a for loop, it also increments the loop variable.
Chapter: 8
Question 6:
What is a goto statement and why is its use generally discouraged?
Answer:
The goto statement is an unconditional jump to another part of the program. It is discouraged because it makes code difficult to follow and understand.
Chapter: 8
Question 7:
Why is it recommended to avoid using break and continue statements in loops?
Answer:
Avoiding break and continue statements makes code easier to read and maintain, as it keeps the flow of control simple and predictable.
Chapter: 8
Question 8:
What is the advantage of adopting a modular approach in programming?
Answer:
A modular approach divides a program into smaller, manageable parts, making it easier to understand, maintain, and modify.
Chapter: 8
Question 9:
What is the rule of single entry and single exit in structured programming?
Answer:
The single entry and single exit rule ensures that a module or construct has only one point of entry and one point of exit, simplifying control flow.
Chapter: 8
Question 10:
How can a switch statement be used to handle different grades in a grading system?
Answer:
A switch statement can be used by assigning a case for each grade, such as 'A', 'B', 'C', etc., and printing the corresponding description for each case.