wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

C conditional statements and loops

Total questions: 55

Worksheet time: 24mins

Name
Class
Date
1.

int sum=10;

for (int i=0;i<=10;i++) {

sum+=i;}

How often does the loop run?

(a)  

2.

int sum=10;

for (int i=0;i<10;i++) {

sum+=i;}

What is the result of sum after the loop?

(a)  

3.

int sum=10;

for (int i=0;i<10;i++) {

sum+=i;}

How often does the loop run?

(a)  

4.

Which type of loop is a for loop?

a)

Pretest

b)

Nontest

c)

Midtest

d)

Posttest

5.

Which of the following is the correct format of a "for" loop?

a)

for(int i = 0; i < 10; i++);

b)

for[int i = 0; i < 10; i++];

c)

for(int i = 0; i < 10; i++)

d)

for[int i = 0; i < 10; i++]

6.

What are the three parts of a for loop?

a)

initialize; test; increment

b)

test; initialize; increment

c)

increment; test; initialize

d)

Larry; Mo; Curly

7.

int i=0;

while (i>0){

cout << "hello";

i++;}

How often does this run?

a)

0

b)

1

c)

infinite

d)

not sure

8.

int i=1;

while (i>0){

cout << "hello";

i++;}

How often does this run?

a)

0

b)

1

c)

infinite

d)

not sure

9.

int i=0;

do{

cout << "hello";

i++;}while (i<0);

How often does this run?

a)

0

b)

1

c)

infinite

d)

not sure

10.

What is the error in the code shown?

a)

avg was not initialized to 0.

b)

avg= sum/i is not how to calculate average.

c)

i does not exist outside of the for loop.

d)

There is no error.

11.

How many loops are there in C?

a)

2

b)

3

c)

4

d)

1

12.

What is currect syntax of for loop?

a)

for(initialization;condition; increment/decrement)

b)

for(increment/decrement; initialization; condition)

c)

for(initialization, condition, increment/decrement

d)

None of These

13.

The statement i++; is equivalent to

a)

i = i + i;

b)

i = i + 1;

c)

i = i - 1;

d)

i --;

14.

What's wrong? for (int k = 2, k <=12, k++)

a)

the increment should always be ++k

b)

the variable must always be the letter i when using a for loop

c)

there should be a semicolon at the end of the statement

d)

the commas should be semicolons

15.

If you want a user to enter exactly 20 values, which loop would be the best to use?

a)

while

b)

switch

c)

do-while

d)

for

16.

What does <= mean?

a)

less than

b)

greater than

c)

less than or equal to

d)

greater than or equal to

17.

Which of the following is NOT a comparison operator in C++ language?

a)

>

b)

<=

c)

=

d)

==

18.

What will be the output of this code?

a)

OK

b)

KO

c)

Depends on compiler

d)

Depends on standard

19.

What is the value of "z" in this code?

a)

The value of z is 10

b)

The value of z is 15

c)

The value of z is 15.6

d)

The value of z is 16

20.

What is output of below program?


int main()

{

int i,j,count;

count=0;

for(i=0; i<5; i++)

{

count++;

}

printf("%d",count);

return 0;

}

a)

5

b)

4

c)

1

d)

0

21.

Number of Keywords present in C Language are .?

a)

32

b)

34

c)

62

d)

64

22.

What is the only function all C programs must contain?

a)

start()

b)

system()

c)

main()

d)

Program()

23.

What is the output of C Program.?

int main()

{

int a;

for(a=25; a <= 27; a++)

{

printf("%d ", a);

}

return 0;

}

a)

25 25 25

b)

25 26 27

c)

27 27 27

d)

Compiler error

24.

What is the result after execution of the following code if a is 10, b is 5, and c is 10?

if ((a > b) && (a <= c))

a = a + 1;

else

c = c+1;

a)

a = 10, c = 10

b)

a = 11, c = 10

c)

a = 10, c = 11

d)

a = 11, c = 11

25.

In switch statement Case Labels must ends with --------

a)

;

b)

:

c)

,

d)

}

26.

----------------- are used in C programming to manipulate the data at bit level

a)

Logical operator

b)

Bitwise operator

c)

Additional operators

d)

None of the above

27.

Every C statement ends with ------------?

a)

.

b)

;

c)

,

d)

}

28.

4. Name the one which is not a looping statement

a)

for

b)

while

c)

do-while

d)

if

29.

The conditional operator are also known as

a)

Relational operator

b)

Binary operator

c)

Ternary operator

d)

Chary operator

30.

What will be the output of following code- for(int i = 1; i < 5; i++ )

{

printf("%d",i);

}

a)

13

b)

135

c)

1234

d)

12345

31.

Select different parts of "for" looping statement-

a)

Initialization part

b)

Condition Part

c)

Update part

d)

All of these

32.
If there is more than one statement in the block of a for loop, which of the following must be placed at the beginning and the ending of the loop block? a.  b.  c. . d. 
a)
parentheses ( )
b)
braces { }
c)
brackets [ ]
d)
arrows < >
33.

This loop starts counting down from 10

a)

for(int i=10; i>0; i--)

b)

int i = 10;

c)

count=10;

d)

for(int i=0; i>0; i--)

34.

Statement lets you run code many times while a condition is true

a)

When

b)

Condition

c)

for

d)

Parentheses

35.

What output is produced by the following segment of code:

for (int i = 0; i < 12; i++)

printf("%d ", i );

a)

0 1 2 3 4 5 6 7 8 9 10 11 12

b)

0 1 2 3 4 5

6 7 8 9 10 11

c)

1 2 3 4 5 6 7 8 9 10

d)

1 2 3 4 5 6 7 8 9

e)

Infinite Loop

36.

What will be the output of the following C code?

#include <stdio.h>

void main()

{

int x = 5;

if (x < 1)

printf("hello");

if (x == 5)

printf("hi");

else

printf("no");

}

a)

hi

b)

hello

c)

no

d)

error

37.

What will be the output of the following C code?

#include <stdio.h>

int main()

{

int x = 0;

if (x == 1)

if (x == 0)

printf("inside if\n");

else

printf("inside else if\n");

else

printf("inside else\n");

}

a)

inside if

b)

inside else if

c)

inside else

d)

compile time error

38.

What will be the output of the following C code?

#include <stdio.h>

int main()

{

int x = 0;

if (x == 1)

if (x >= 0)

printf("true\n");

else

printf("false\n");

}

a)

Depends on the compiler

b)

No print statement

c)

True

d)

False

39.

The switch statement takes a given integer value then seeks a matching value among a number of _______ statements.

a)

break

b)

case

c)

switch

d)

goto

40.

How many loops are there in C

a)

1

b)

3

c)

2

d)

4

41.

Which of the following is an exit control statement

a)

for

b)

while

c)

do while

d)

continue

42.

The value of i after the execution of the following segment is

i = 2;

for( i=0; i>10; i=i+1);

a)

1

b)

2

c)

0

d)

11

43.

The output of the following segment is

int k, n=20;

k=(n>5?(n<=10?100:200):500);

printf("%d",n);

a)

100

b)

200

c)

300

d)

20

44.

C language developed at _____?

a)

AT & T's Bell Laboratories of USA in 1972

b)

AT & T's Bell Laboratories of USA in 1970

c)

Sun Microsystems in 1973

d)

Cambridge University in 1972

45.

which is the only function all C programs must contain?

a)

start()

b)

sys()

c)

main()

d)

scanf()

46.

Which of the following is not a correct variable type?

a)

float

b)

real

c)

int

d)

double

47.

What will be the output of the following C code?

#include <stdio.h>

int main()

{

int a = 1, b = 1, c;

c = a++ + b;

printf("%d, %d", a, b);

}

a)

a=1, b=1

b)

a=2, b=1

c)

a=1, b=2

d)

a=2, b=2

48.

What will be the output of the following C code?

#include <stdio.h>

int main()

{

int i = 0;

int j = i++ + i;

printf("%d\n", j);

}

a)

0

b)

1

c)

2

d)

compile time error

49.

What will be the output of the following C code?

#include <stdio.h>

int main()

{

int a = 1, b = 1;

switch (a)

{

case a*b:

printf("yes ");

case a-b:

printf("no\n");

break;

}

}

a)

yes

b)

no

c)

yes no

d)

compile time error

50.

Library function pow() belongs to which header file?

a)

math.h

b)

square.h

c)

stdio.h

d)

conio.h

51.

Is it possible to run program without main() function?

a)

yes

b)

no

c)

may be

52.

How many main() function we can have in our project?

a)

1

b)

2

c)

no limit

d)

depends on the program

53.

int x = 10;


int main()

{

int x = 0;

printf("%d",x);

return 0;

}

a)

10

b)

0

c)

compile error

d)

undefined

54.

What should be the output:

int main()

{

int a = 10/3;

printf("%d",a);

return 0;

}

a)

3.33

b)

3.0

c)

3

d)

0

55.

#include "stdio.h"

int main()

{

int a = 10;

printf("%d", a);

int a = 20;

printf("%d",a);

return 0;

}

a)

1020

b)

1010

c)

2020

d)

Error: Redeclaration of a