wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Loop Control Statement in C

Total questions: 41

Worksheet time: 26mins

Name
Class
Date
1.

The keyword ‘break’ cannot be simply used within

a)

do-while

b)

if-else

c)

for

d)

while

2.

Which keyword is used to come out of a loop only for that iteration?

a)

break

b)

continue

c)

return

d)

None of the mentioned

3.

Which loop is guaranteed to execute at least one time.

a)

while

b)

do while

c)

for

d)

None of the above

4.

Switch statement accepts.

a)

int

b)

char

c)

long

d)

All of the above

5.

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

6.

What is the output of this program?

void main()

{

if(!printf(""))

printf("hello");

else

printf("world");

}

a)

hello

b)

world

c)

Compilation Error

d)

None of the above

7.

What is the output of this C code?

void main()

{

int i = 0;

if (i == 0)

{

printf("Hello");

break;

}

}

a)

Hello is printed infinite times

b)

Hello

c)

varies

d)

compile time error

8.

What is the output of C Program.?

int main()

{

int a=5;

while(a==5)

{

printf("RABBIT");

break;

}


return 0;

}

a)

RABBIT is printed unlimited number of times

b)

RABBIT

c)

Compiler error

d)

None of the above.

9.

What is the output of C Program.?

int main()

{

int a=5;

while(a >= 3);

{

printf("RABBIT\n");

break;

}

printf("GREEN");

return 0;

}

a)

GREEN

b)

RABBIT GREEN

c)

RABBIT is printed infinite times

d)

None of the above

10.

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;

}

a)

No Output

b)

32 33 34

c)

32 33 34 35

d)

Compiler error

11.

What is the output of C Program.?

int main()

{

int k;

for(k=1; k <= 5; k++);

{

printf("%d ", k);

}

return 0;

}

a)

1 2 3 4 5

b)

1 2 3 4

c)

6

d)

5

12.

What is the output of C Program.?

int main()

{

int k;

for(;;)

{

printf("TESTING\n");

break;

}

return 0;

}

a)

No Output

b)

TESTING

c)

Compiler error

d)

None of the above

13.

What is the output of C Program.?

int main()

{

int k;

for(printf("FLOWER "); printf("YELLOW "); printf("FRUITS "))

{

break;

} return 0;

}

a)

Compiler error

b)

FLOWER FRUITS

c)

FLOWER YELLOW

d)

FLOWER YELLOW FRUITS

14.

What is the output of C Program.?

int main()

{

int a=5;

while(a=123)

{

printf("RABBIT\n");

break;

}

printf("GREEN");

return 0;

}

a)

GREEN

b)

RABBIT GREEN

c)

RABBIT is printed unlimited number of times.

d)

Compiler error.

15.

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);

}

a)

Syntax error in declaration of 'a' variable

b)

No errors, program will show the output 5

c)

Redeclaration of a in same scope throws error

d)

a is out of scope when printf is called

16.

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);

}

a)

11 3 5 11

b)

11 1 5 11

c)

11 3 2 11

d)

11 3 3 11

17.

What is the output of this program?

void main()

{

int x=0;

for(;;)

{

if(x==3)

break;

printf("%d ",++x);

}

}

a)

1 2 3

b)

0 1 2 3

c)

1 2

d)

Compilation Error

18.

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;

}

a)

5 times

b)

10 times

c)

0 times

d)

Infinite times

19.

What is the final value of i after the for loop

for(int i=0; i<10; i++) {} is run?

a)

10

b)

9

c)

0

d)

1

20.

How many times i value is checked in the above code?

a)

2

b)

3

c)

4

d)

1

21.

What is the output of this C code?

a)

In while loop

b)

In while loop After loop

c)

After loop

d)

Infinite loop

22.

What is the output of this C code?

a)

Compile time error

b)

Hi Hi

c)

Hi

d)

Varies

23.

What's the output of the above code?

a)

1 2 3 4 5

b)

0 1 2 3 4

c)

0 0 0 0 0

d)

0 1 2 3 4 5

24.

What's the output of the above C code?

a)

One

b)

Two

c)

Compile Error

d)

Invalid

25.

What is the output of this C code?

a)

0 1 2 3 4 5

b)

0 1 2 3 4

c)

0 0 0 0

d)

0 1 2 3

26.
How would you round off a value from 1.66 to 2.0?
a)
ceil(1.66)
b)
floor(1.66)
c)
roundup(1.66)
d)
roundto(1.66)
27.
Which of the following statements should be used to obtain a remainder after dividing 3.14 by 2.1 ?
a)
rem = 3.14 % 2.1;
b)
rem = modf(3.14, 2.1);
c)
rem = fmod(3.14, 2.1);
d)
Remainder cannot be obtain in floating point division
28.
Point out the error in the following program
a)
Error: Declaration syntax error 'v' (or) Size of v is unknown or zero.
b)
Program terminates abnormally.
c)
No error
d)
None of these.
29.
In which order do the following gets evaluated
1.Relational
2.Arithmetic
3.Logical
4.Assignment
a)
2134
b)
1234
c)
4321
d)
3214
30.

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;

}

a)

10

b)

5

c)

11

d)

0

31.

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;

}

a)

Welcome Programmer

b)

Error: Undeclared identifier if

c)

Error: Expression syntax

d)

No output

32.

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

a)

1 and 4

b)

1, 2, and 3

c)

1, 2, 3 and 4

d)

1, 3 and 4

33.

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;

}

a)

-1

b)

5

c)

0

d)

Compilation error

34.
a)

GREEN

b)

RABBIT

GREEN

c)

RABBIT is printed unlimited number of times.

d)

None of the above

35.
a)

FALSE

b)

Error

c)

TRUE

d)

None

36.
a)

Compilation error

b)

-128

c)

0

d)

1

37.
a)

Compilation error

b)

Program never ends

c)

loop loop loop loop loop

d)

None of these

38.
a)

2 4

b)

No output

c)

2 4 6

d)

Program never ends

39.
a)

Compilation error

b)

Program never ends

c)

Hello

d)

None of the above

40.
a)

Nothing prints

b)

for

c)

for for for

d)

None of the above

41.

In the following loop construct, which one is executed only once always.

for(exp1; exp2; exp3)

a)

exp1

b)

exp2

c)

exp3

d)

All of these