C Do While Looping MCQ
Q1) Choose a right C Statement.
- Loops or Repetition block executes a group of statements repeatedly.
- Loop is usually executed as long as a condition is met.
- Loops usually take advantage of Loop Counter
- All the above.
Answer:- (D).
Explanations :None.
Explanations :None.
- While Block
- For Block
- Do While Block
- All the above
Answer:- (D).
Explanations :None.
Explanations :None.
- for
- while
- do while
- All work at same speed
Answer:- (D).
Explanations :None.
Explanations :None.
- while(condition)
{
//statements
} - {
//statements
}while(condition) - while(condition);
{
//statements
} - while()
{
if(condition)
{
//statements
}
}
Answer:- (A).
Explanations :None.
Explanations :None.
- for(initalization; condition;
incrementoperation)
{
//statements
} - for(declaration; condition; incrementoperation)
{
//statements
} - for(declaration; incrementoperation; condition)
{
//statements
} - for(initalization; condition;
incrementoperation;)
{
//statements
}s
Answer:- (A).
Explanations :increment or decrement operation at third place.
Explanations :increment or decrement operation at third place.
- dowhile(condition)
{
//statements
} - do while(condition)
{
//statements
} - do
{
//statements
}while(condition) -
do
{
//statements
}while(condition);
Answer:- (D).
Explanations :Semicolon after while(condition) is a must.
Explanations :Semicolon after while(condition) is a must.
int main() { while(true) { printf("RABBIT"); break; } return 0; }
- RABBIT
- RABBIT is printed unlimited number of times.
- No output
- Compiler error.
Answer:- (D).
Explanations :while(TRUE) or while(true) does not work. true is not a keyword.
Explanations :while(TRUE) or while(true) does not work. true is not a keyword.
int main() { int a=5; while(a==5) { printf("RABBIT"); break; } return 0; }}
- RABBIT is printed unlimited number of times
- RABBIT
- Compiler error
- None of the above.
Answer:- (B).
Explanations :If there is no BREAK statement, while loop runs continuously util the computer hangs. BREAK causes the loop to break once and the statement below the while if any will be executed.
Explanations :If there is no BREAK statement, while loop runs continuously util the computer hangs. BREAK causes the loop to break once and the statement below the while if any will be executed.
int main() { int a=5; while(a=123) { printf("RABBIT\n"); break; } printf("GREEN"); return 0; }
- GREEN
- RABBIT GREEN
- RABBIT is printed unlimited number of times.
- Compiler error.
Answer:- (B).
Explanations :while(a=123) = while(123) = while(Non Zero Number). So while is executed. BREAK breaks the loop immediately. Without break statement, while loop runs infinite number of times.
Explanations :while(a=123) = while(123) = while(Non Zero Number). So while is executed. BREAK breaks the loop immediately. Without break statement, while loop runs infinite number of times.
int main() { int a=5; while(a >= 3); { printf("RABBIT\n"); break; } printf("GREEN"); return 0; }
- GREEN
- RABBIT GREEN
- RABBIT is printed infinite times/li>
- None of the above
Answer:- (D).
Explanations :Notice a semicon(;) after while condition. It makes the printf and break statement blocks isolate.
while(a >= 3)
{
;//infinite loop
}
{
printf("RABBIT\n");
break;
}
Explanations :Notice a semicon(;) after while condition. It makes the printf and break statement blocks isolate.
while(a >= 3)
{
;//infinite loop
}
{
printf("RABBIT\n");
break;
}
Copyright © 2022 Shineskill Software Pvt. Ltd., All rights reserved.