Short Q/A Conditional Control Structure - Students Free Notes

What will be the output of the following code?

char ch; ch = ‘c’; switch (ch) { case ‘a’: printf(“Good Morning!”); break; case ‘b’: printf(“Have a Nice Day!”); break; case ‘c’: case ‘d’: case ‘e’: printf(“Good Bye!”); break; } Output: The value of ch is ‘c’, so the program will match case ‘c’, but because there is no break statement immediately after it, the … Read more

What is a nested selection structure?

A nested selection structure is when one control structure (like an if, else-if, or switch) is placed inside another. This allows for more complex decision-making, as the inner control structure is executed only if the outer structure’s condition is true. For example, in an if statement, another if or else-if statement can be placed within … Read more

Differentiate between else-if and switch selection structures. 

Both else-if and switch are used to handle multiple conditions, but they differ in usage. The else-if structure is a sequence of if statements where each condition is checked one after the other, and the first condition that evaluates to true executes its corresponding block of code. It is useful when conditions are based on … Read more

Differentiate between if and if-else selection structures.

The if and if-else selection structures are both used to make decisions in programming. In an if statement, a condition is evaluated, and if the condition is true, the subsequent block of code is executed. If the condition is false, no code is executed unless an alternative is explicitly provided. The if-else structure, however, provides … Read more