Decision Constructs Short Questions and Answers

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.

 

decision constructs short questions and answers

Chapter No.11: Decision Constructs

Short Questions and Answers

Q.1: Define control structure?
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.
 
Q.2: What is sequence-structure?
Answer:

In sequence structure, instructions are executed in the same order in which they are specified in the program.
 
Q.3: What is the compound statement?
Answer:
A compound statement refers to a group of statements enclosed in opening and closing braces such as:

{
Statement-1;
Statement-2;
-
-
-
Statement-n;

}

 
Q.4: Define selection structure?
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
 
Q.5: What is loop structure? OR What is repetition structure?
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
 
Q.6: What is a condition?
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
 
Q.7: Define simple if statement?
Answer:
if statement is the simplest form of decision constructs. It allows a statement or a set of statements to be executed conditionally. 
The general form of simple if statement is as under:


if(condition)
{
Statement-1;
Statement-2;
-
-
-
Statement-n;

} 

Q.8: Define if-else statement?
Answer:
The keyword else is used to specify two different choices with the statement. 
The general form of if-else statement is as under:


if(condition)
{
block of if (true case);
}
else
{
block of if (false case);
}


Q.9: What is a flowchart? And write some its benefits.
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);
}

}

  
Q.11: Differentiate between nested if and sequence of ifs?
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.
 
Q.12: What is if-else if statement?
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;
 
Q.13: What is switch statement?
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.
 
Q.14: Differentiate between break and default in switch statement?
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.
 
Q.15: What is conditional operator?
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 -     MCQs

➤ Decision Constructs - Short Questions

➤ Decision Constructs - Exercise Programs 

➤ Loop Constructs - Exercise Programs

➤ Loop Constructs - Short Questions

➤ Loop Constructs - MCQs

➤ Input/Output - Short Questions

➤ Input/Output - MCQs

2 Comments

Your feedback is highly appreciated and will help us to improve. So, please give your good suggestions.

  1. Thanks for this posts... 👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍✌✌👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍

    ReplyDelete

Post a Comment

Your feedback is highly appreciated and will help us to improve. So, please give your good suggestions.

Previous Post Next Post