Decision Constructs Short
Questions and Answers. This is the 1st post
for ICS Part-II | 2nd Year Computer Science Chapter
No.11. The given short questions along with answers are important for the
final exams.
We have tried our best to make the important short
questions and answers from this chapter (Decision Constructs).
This post covers the topics i.e., control structures (sequence, selection, and
loop), simple if statement, if-else statement, if-else if statement, comparison
of nested if & sequence of ifs statements, switch statement, and
conditional operator.
Chapter No.11: Decision Constructs
Short Questions and Answers
Answer:
Control structures are statements used to control the flow of execution in a program or function. The C control structures enable us to group individual instructions into a single logical unit with one entry point and one exit point. Sequence, selection, and repletion are the type of control structures.
Answer:
In sequence structure, instructions are executed in the same order in which they are specified in the program.
Answer:
A compound statement refers to a group of statements enclosed in opening and closing braces such as:
{
Statement-1;
Statement-2;
-
-
-
Statement-n;
}
Answer:
A selection structure chooses which statement or a block of statement is to execute. In C, there are two basic selection statements:
- if-else
- switch
Answer:
Loop (repetition) is also called iteration. It is a control structure, which repeats a statement or a group of statements in a program. In C, there are three basic loop statements:
- while loop
- do-while loop
- for loop
Answer:
A condition is an expression that either evaluates to true (1) or false (0). The result of this evaluation can be assigned to a variable
Answer:
if statement is the simplest form of decision constructs. It allows a statement or a set of statements to be executed conditionally.
if(condition)
{
Statement-1;
Statement-2;
-
-
-
Statement-n;
Answer:
The keyword else is used to specify two different choices with the statement.
{
block of if (true case);
}
else
{
block of if (false case);
}
Answer:
A flowchart is the pictorial representation of a program. Its benefits are:
- Easy to understand the program logic
- Easy to write the program
- Easy to debug the program
- Easy to modify the program
Q.10: Define nested if statement? Also, write its general form.
Answer:
Nested if statement means an if statement inside another if statement. Nesting can be done up to any level. The programmer may use as many if statements inside another if statement as he wants, however it increases the complexity of the nested if statement.
General form:
if(condition)
{
If (condition)
{
Block of if (true case);
}
}
Answer:
In the case of nested if statement, when the control flow reaches a logical decision, the rest of the conditions are skipped whereas in a sequence of if statements, all conditions are tested in any case.
Answer:
if-else if statement is suitable where there are multiple alternatives. It is an alternative statement of nested if and sequence of ifs statements.
General Form:
if(condition-1)
Statement-1;
else if(condition-2)
statement-2;
-
-
-
else if(condition-n)
statement-n;
else
Statement-k;
Answer:
The switch statement is an alternative of if-else if statement. It is especially useful when the selection is based on the value. It can also be used in C to select one of many alternatives, like if statement, it is also a conditional statement that compares the value of an expression against a list of cases. The case label can be integral or character constant. Similarly, the value of the expression must be an integer or a character.
Answer:
break: The break causes the rest of the switch statement to be skipped.
default: If all break statements are omitted from the switch statement, the code from the first true case down to the end of switch statement will execute sequentially. A default label may be used to provide code to be executed if none of the case label is matched.
Answer:
Conditional operator is used as an alternative to the if-else statement. It is a ternary operator.
General Form:
Conditional expression? True-case statement : false-case statement;
Q.16: What is the output of the following program?
main( )
{
int score=80;
if(score>=90)
printf(“India\t”);
if(score>=80)
printf(“Pakistan\t”);
if(score>=70)
printf(“UAE\t”);
if(score>=60)
printf(“Turkey”);
}
Answer:
The output of the above code is as under:
Pakistan UAE Turkey
Q.17: What is the output of the following code?
main( )
{
int a=-10;
(a>4) ? printf(“%d”,++a)
: printf(“%d”, --a);
}
Answer:
The output of the above code is as under:
-11
The following may relate to you!
➤ Decision Constructs - Short Questions
➤ Decision Constructs - Exercise Programs
➤ Loop Constructs - Exercise Programs
➤ Loop Constructs - Short Questions
Thanks for this posts... 👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍✌✌👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍
ReplyDeleteThanks, it's all for you dear!
DeletePost a Comment
Your feedback is highly appreciated and will help us to improve. So, please give your good suggestions.