wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Loop in C

Total questions: 51

Worksheet time: 31mins

Name
Class
Date
1.

Loops in C Language are implemented using?

a)

While Block

b)

For Block

c)

Do While Block

d)

All the above

2.

Which loop is faster in C Language, for, while or Do While?

a)

for

b)

while

c)

do while

d)

All work at same speed

3.

If block always need to be associated with a else block?

a)

True

b)

False

4.

Choose a right C Statement.

a)

Loops or Repetition block executes a group of statements repeatedly

b)

Loop is usually executed as long as a condition is met

c)

Loops usually take advantage of Loop Counter

d)

All the above

5.

The conditional operator are also known as

a)

Relational operator

b)

Binary operator

c)

Ternary operator

d)

Chary operator

6.

If you have to make decision based on multiple choices, which of the following is best suited?

a)

if

b)

if-else

c)

if-else-if

d)

All the above

7.

Can we use string inside switch statement?

a)

Yes

b)

No

8.

In situations where we need to execute body of the loop before testing the condition, we should use __________.

a)

for

b)

while

c)

do while

d)

nested for loop

9.

Choose a correct C Statement.

a)

a++ is (a=a+1) POST INCREMENT Operator

b)

a-- is (a=a-1) POST DECREMENT Opeartor

--a is (a=a-1) PRE DECREMENT Opeator

c)

++a is (a=a+1) PRE INCREMENT Operator

d)

All the above.

10.

What is the way to suddenly come out of or Quit any Loop in C Language.?

a)

continue; statement

b)

leave; statement

c)

break; statement

d)

quit; statement

11.

The keyword ‘break’ cannot be simply used within

a)

do-while

b)

if-else

c)

for

d)

while

12.

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

13.

Which loop is guaranteed to execute at least one time.

a)

while

b)

do while

c)

for

d)

None of the above

14.

Switch statement accepts.

a)

int

b)

char

c)

long

d)

All of the above

15.

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

16.

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

17.

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

18.

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.

19.

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

20.

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

21.

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

22.

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

23.

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

24.

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.

25.

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

26.

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

27.

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

28.

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

29.

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

30.

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

a)

2

b)

3

c)

4

d)

1

31.

What is the output of this C code?

a)

In while loop

b)

In while loop After loop

c)

After loop

d)

Infinite loop

32.

What is the output of this C code?

a)

Compile time error

b)

Hi Hi

c)

Hi

d)

Varies

33.

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

34.

What's the output of the above C code?

a)

One

b)

Two

c)

Compile Error

d)

Invalid

35.

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

36.
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)
37.
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
38.
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.
39.
In which order do the following gets evaluated
1.Relational
2.Arithmetic
3.Logical
4.Assignment
a)
2134
b)
1234
c)
4321
d)
3214
40.

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

41.

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

42.

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

43.

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

44.
a)

GREEN

b)

RABBIT

GREEN

c)

RABBIT is printed unlimited number of times.

d)

None of the above

45.
a)

FALSE

b)

Error

c)

TRUE

d)

None

46.
a)

Compilation error

b)

-128

c)

0

d)

1

47.
a)

Compilation error

b)

Program never ends

c)

loop loop loop loop loop

d)

None of these

48.
a)

2 4

b)

No output

c)

2 4 6

d)

Program never ends

49.
a)

Compilation error

b)

Program never ends

c)

Hello

d)

None of the above

50.
a)

Nothing prints

b)

for

c)

for for for

d)

None of the above

51.

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