C Decision making & Loops-2
1. Which keyword can be used for coming out of recursion?
a) return
b) break
c) exit
d) both A and B
Answer: A
Return is used for coming out of recursion.
2. goto can be used to jump from main to within a function?
a) True
b) False
Answer: B
goto statement in C programming provides an unconditional jump from the goto to a labeled statement in the same function.
3. Which of the following is an invalid if-else statement?
a) if (if (a == 1)){}
b) if (a){}
c) if ((char) a){}
d) if (func1 (a)){}
Answer: A
No explanation is given for this question.
4. Switch statement accepts
a) int
b) char
c) long
d) All of the above
Answer: D
switch statment accepts all int , char and long.
5. Which loop is guaranteed to execute at least one time?
a) for
b) while
c) do while
d) None of the above
Answer: C
In do while first the statements in the body are executed then the condition is checked. If the condition is true then once again statements in the body of do while are executed.
6. A labeled statement consist of an identifier followed by
a) ;
b) :
c) ,
d) =
Answer: B
The label is an identifier. When goto statement is encountered, control of the program jumps to label and starts executing the code.
7. do-while loop terminates when conditional expression returns?
a) One
b) Zero
c) Non - zero
d) None of the above
Answer: B
zero indicate False which terminate the loop.
8. For loop in a C program, if the condition is missing?
a) it is assumed to be present and taken to be false
b) it is assumed to be present and taken to the true
c) it result in a syntax error
d) execution will be terminated abruptly
Answer: B
No explanation is given for this question.
9. Which of the following statement about for loop is true?
a) Index value is retained outside the loop
b) Index value can be changed from within the loop
c) Goto can be used to jump, out of the loop
d) All of these
Answer: D
No explanation is given for this question.
10. Using goto inside for loop is equivalent to using
a) Continue
b) Break
c) Return
d) None of the above
Answer: D
Goto statement is rarely used in loops, we can not use continue, break & return instead of goto.