NEW
Font size
WorksheetsLoop in C
Total questions: 51
Worksheet time: 31mins
Loops in C Language are implemented using?
While Block
For Block
Do While Block
All the above
Which loop is faster in C Language, for, while or Do While?
for
while
do while
All work at same speed
If block always need to be associated with a else block?
True
False
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
The conditional operator are also known as
Relational operator
Binary operator
Ternary operator
Chary operator
If you have to make decision based on multiple choices, which of the following is best suited?
if
if-else
if-else-if
All the above
Can we use string inside switch statement?
Yes
No
In situations where we need to execute body of the loop before testing the condition, we should use __________.
for
while
do while
nested for loop
Choose a correct C Statement.
a++ is (a=a+1) POST INCREMENT Operator
a-- is (a=a-1) POST DECREMENT Opeartor
--a is (a=a-1) PRE DECREMENT Opeator
++a is (a=a+1) PRE INCREMENT Operator
All the above.
What is the way to suddenly come out of or Quit any Loop in C Language.?
continue; statement
leave; statement
break; statement
quit; statement
The keyword ‘break’ cannot be simply used within
do-while
if-else
for
while
Which keyword is used to come out of a loop only for that iteration?
break
continue
return
None of the mentioned
Which loop is guaranteed to execute at least one time.
while
do while
for
None of the above
Switch statement accepts.
int
char
long
All of the above
For loop in a C program, if the condition is missing?
it is assumed to be present and taken to be false
it is assumed to be present and taken to the true
it result in a syntax error
execution will be terminated abruptly
What is the output of this program?
void main()
{
if(!printf(""))
printf("hello");
else
printf("world");
}
hello
world
Compilation Error
None of the above
What is the output of this C code?
void main()
{
int i = 0;
if (i == 0)
{
printf("Hello");
break;
}
}
Hello is printed infinite times
Hello
varies
compile time error
What is the output of C Program.?
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.
What is the output of C Program.?
int main()
{
int a=5;
while(a >= 3);
{
printf("RABBIT\n");
break;
}
printf("GREEN");
return 0;
}
GREEN
RABBIT GREEN
RABBIT is printed infinite times
None of the above
What is the output of C Program.?
int main()
{
int a=32;
do
{
printf("%d ", a);
a++;
if(a > 35)
break;
}
while(1);
return 0;
}
No Output
32 33 34
32 33 34 35
Compiler error
What is the output of C Program.?
int main()
{
int k;
for(k=1; k <= 5; k++);
{
printf("%d ", k);
}
return 0;
}
1 2 3 4 5
1 2 3 4
6
5
What is the output of C Program.?
int main()
{
int k;
for(;;)
{
printf("TESTING\n");
break;
}
return 0;
}
No Output
TESTING
Compiler error
None of the above
What is the output of C Program.?
int main()
{
int k;
for(printf("FLOWER "); printf("YELLOW "); printf("FRUITS "))
{
break;
} return 0;
}
Compiler error
FLOWER FRUITS
FLOWER YELLOW
FLOWER YELLOW FRUITS
What is the output of C Program.?
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.
What is the output of this program?
#include <stdio.h>
int main()
{
int i;
for (i = 0;i < 5; i++)
int a = i;
printf("%d", a);
}
Syntax error in declaration of 'a' variable
No errors, program will show the output 5
Redeclaration of a in same scope throws error
a is out of scope when printf is called
What is the output of this program?
#include <stdio.h>
void main()
{
int a=1, b=2, c=3, d;
d = (a=c, b+=a, c=a+b+c);
printf("%d %d %d %d", d, a, b, c);
}
11 3 5 11
11 1 5 11
11 3 2 11
11 3 3 11
What is the output of this program?
void main()
{
int x=0;
for(;;)
{
if(x==3)
break;
printf("%d ",++x);
}
}
1 2 3
0 1 2 3
1 2
Compilation Error
How many times letsfindcourse will be printed?
#include <stdio.h>
int main()
{
int i = -5;
while (i <= 5)
{
if (i >= 0)
break;
else
{
i += 1;
continue;
}
printf("letsfindcourse");
}
return 0;
}
5 times
10 times
0 times
Infinite times
What is the final value of i after the for loop
for(int i=0; i<10; i++) {} is run?
10
9
0
1
How many times i value is checked in the above code?
2
3
4
1
What is the output of this C code?
In while loop
In while loop After loop
After loop
Infinite loop
What is the output of this C code?
Compile time error
Hi Hi
Hi
Varies
What's the output of the above code?
1 2 3 4 5
0 1 2 3 4
0 0 0 0 0
0 1 2 3 4 5
What's the output of the above C code?
One
Two
Compile Error
Invalid
What is the output of this C code?
0 1 2 3 4 5
0 1 2 3 4
0 0 0 0
0 1 2 3
1.Relational
2.Arithmetic
3.Logical
4.Assignment
How many times "I'm a Programmer" will be printed ?#include<stdio.h>
int main() {
int x;
for(x=-1; x<=10; x++) {
if(x < 5)
continue;
else
break;
printf("I'm a Programmer");
}
return 0;
}
10
5
11
0
What is the output of the code ?
#include<stdio.h>
int main() {
int i = 8, j = 24;
if(i = 8) && if(j = 24) printf("Welcome Programmer");
return 0;
}
Welcome Programmer
Error: Undeclared identifier if
Error: Expression syntax
No output
Which statements are correct about an if-else statement in a C-program?
1. Nested if-else statements are allowed
2. Every if-else statement can be replaced by an equivalent statement using ?: operators
3. Multiple statement in else block are allowed
4. Multiple statement in if block are allowed
1 and 4
1, 2, and 3
1, 2, 3 and 4
1, 3 and 4
Find the output of the program ?
#include<stdio.h>
int main()
{
int a=5;
do
{
printf("%d\n",a);
a= -1;
}while (a>0);
return 0;
}
-1
5
0
Compilation error
GREEN
RABBIT
GREEN
RABBIT is printed unlimited number of times.
None of the above
FALSE
Error
TRUE
None
Compilation error
-128
0
1
Compilation error
Program never ends
loop loop loop loop loop
None of these
2 4
No output
2 4 6
Program never ends
Compilation error
Program never ends
Hello
None of the above
Nothing prints
for
for for for
None of the above
In the following loop construct, which one is executed only once always.
for(exp1; exp2; exp3)
exp1
exp2
exp3
All of these
