Question{04}: Which statement is true about \"if\" and \"switch\" statements? A.
ID: 3860898 • Letter: Q
Question
Question{04}: Which statement is true about "if" and "switch" statements?
A. they can be used to control the flow of your code
B. they can use combinations of logicals in their expression
C. in some situations, they can be used interchangeably
D. they can be used to selectively run lines of code based on a condition
or expression
E. all of the above
Answer{04}='';
Reason{04}='';
Question{05}: Which statement is true about the "else" and "otherwise"
A. an "else" is not required
B. they can be used to "handle" unexpected situations
C. an "otherwise" is not required
D. they both imply false (or that none of the previous expressions have
evaluated to true
E. all of the above
Answer{05}='';
Reason{05}='';
Question{06}: Which statement is true about a "for" loop?
A. its values are limited to only integer values
B. it can not be used to iterate (or loop) through characters/strings
C. it is best used when the number of loops is unknown (at design time)
D. it may be "nested" to allow for looping through multi dimensional
arrays
E. none of the above
Answer{06}='';
Reason{06}='';
Explanation / Answer
Answer{04}=E
Reason{04}=IF and SWITCH both are control statements which are used to control the flow of the
program.
They both takes any type of logical combination in their expression.
Both can be used interchangeably for example lets see example below:
if(option == 1) // Checking if user selected option 1
{
//perform some operations
}
if(option==2)
{
//perform operation
}
above code can also be written as follow:
switch(option)
{
case 1:
//perform some operation
break;
case 2:
//perform some operations
beak;
}
Answer{05} D
Reason{05}= they both imply false (or that none of the previous expressions have
evaluated to true.they are not used to handle unexpected siyutaions. in that case
we use exception handling.Both else and otherwise are required in case previous statement evaluated false;
Answer{06} D
Reason{06}=for loop can be used to loop over String . by accessing one character at atime.
It is best when no of loops is known. In case loops are unknown we must
prefer while loop. So all three A,B,C are wrong. Yes D option is right because
it may be "nested" to allow for looping through multi dimensional
arrays
for(int i=0;i<10;i++)
{
for(int j=0;j<10;j++)
{
printf(%d %d,i,j)
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.