QUIZ ON : C LANGUAGE - CONDITIONAL STATEMENTS AND LOOPS

CONDITIONAL STATEMENTS AND LOOPS

00:00:00

What is the final value of x when the code int x; for(x=0; x<10; x++) {} is executed?

Option A. 10
Option B. 9
Option C. 0
Option D. 1
True Answer A

Explanation :

What is the final value of x when the code int x; for(x=0; x<10; x++) {} is executed?

Question No# : 01 out of 20



What will be the output of the following code segment?

int a = 100, b = 74;
if (a++ > 100 && b++ > 200)
printf("High values with a = %d b = %d\n", a, b);
if (a++ < 100 || b++ < 200)
printf("Low values with a = %d b = %d\n", a, b);

Option A. High values with a = 101 b = 74
Option B. Low values with a = 102 b = 75
Option C. High values with a = 102 b = 75
Option D. Low values with a = 101 b = 74
True Answer B

Explanation :

What will be the output of the following code segment?

int a = 100, b = 74;
if (a++ > 100 && b++ > 200)
printf("High values with a = %d b = %d\n", a, b);
if (a++ < 100 || b++ < 200)
printf("Low values with a = %d b = %d\n", a, b);

Question No# : 02 out of 20



The do..while looping statement

Option A. is executed only once if the conditions is true
Option B. is also known as entry-controlled loop
Option C. is executed at least once if the conditions is false
Option D. the unconditional loop
True Answer C

Explanation :

The do..while looping statement

Question No# : 03 out of 20

break keyword is mandatory in switch case structure.

Option A. TRUE
Option B. FALSE
Option C.
Option D.
True Answer B

Explanation :

break keyword is mandatory in switch case structure.

Question No# : 04 out of 20

What is the value of r after this code is executed?

r=2;
k=8;
if (r>3 || k>6 && r<5 ||k>10)
r=9;
else
r=6

Option A. 9
Option B. 2
Option C. 6
Option D. 8
True Answer A

Explanation :

What is the value of r after this code is executed?

r=2;
k=8;
if (r>3 || k>6 && r<5 ||k>10)
r=9;
else
r=6

Question No# : 05 out of 20



All of the following are valid expressions in C.

if a( = 6) b = 5;
a = b = c = 5;
a = 11 % 3

Option A. TRUE
Option B. FALSE
Option C.
Option D.
True Answer B

Explanation :

All of the following are valid expressions in C.

if a( = 6) b = 5;
a = b = c = 5;
a = 11 % 3

Question No# : 06 out of 20



Which of the following cannot be checked in a switch case statement?

Option A. Character
Option B. Integer
Option C. Float
Option D. enum
True Answer C

Explanation :

Which of the following cannot be checked in a switch case statement?

Question No# : 07 out of 20



A programming construct in which a set of statement in a computer program can be executed repeatedly.

Option A. Loop statement
Option B. Conditional Statement
Option C. Block Statement
Option D. All of the above
True Answer A

Explanation :

A programming construct in which a set of statement in a computer program can be executed repeatedly.

Question No# : 08 out of 20

Which code will print k 20 times?

Option A. for (i=1; i < 20; i++) printf (“k”);
Option B. for (i=1; i = 20; i++) printf (“k”);
Option C. for (i=0; i < 20; i++) printf (“k”);
Option D. for (i=0; i <= 20; i++) printf (“k”);
True Answer C

Explanation :

Which code will print k 20 times?

Question No# : 09 out of 20



How many times is a do while loop guaranteed to loop?

Option A. 0
Option B. Infinitely
Option C. 1
Option D. Variable
True Answer C

Explanation :

How many times is a do while loop guaranteed to loop?

Question No# : 10 out of 20



If we have to execute the program with different set of inputs, we need to recompile the program each time.

Option A. TRUE
Option B. FALSE
Option C.
Option D.
True Answer B

Explanation :

If we have to execute the program with different set of inputs, we need to recompile the program each time.

Question No# : 11 out of 20

It is necessary to have default case in a switch statement.

Option A. TRUE
Option B. FALSE
Option C.
Option D.
True Answer B

Explanation :

It is necessary to have default case in a switch statement.

Question No# : 12 out of 20

What will be the output of the following program?

main()
{
int x = 5;
while ( x = = 1)
x = x -1;
printf ( “ %d\n”, x);
}

Option A. 5
Option B. 4
Option C. 0
Option D. syntax error
True Answer A

Explanation :

What will be the output of the following program?

main()
{
int x = 5;
while ( x = = 1)
x = x -1;
printf ( “ %d\n”, x);
}

Question No# : 13 out of 20



Which of the following is not an iterative statement?

Option A. switch
Option B. while
Option C. do while
Option D. for
True Answer A

Explanation :
Switch is an Conditional Statement

Which of the following is not an iterative statement?

Question No# : 14 out of 20



A break statement is used to exit from a statement block in a switch statement.

Option A. TRUE
Option B. FALSE
Option C.
Option D.
True Answer A

Explanation :

A break statement is used to exit from a statement block in a switch statement.

Question No# : 15 out of 20

Which of the following is not an unconditional control statement in ‘C’?

Option A. break
Option B. continue
Option C. exit()
Option D. while
True Answer C

Explanation :

Which of the following is not an unconditional control statement in ‘C’?

Question No# : 16 out of 20



What would be value of j after the following is executed?

k=17;
j=6;
if (k < 10)
j=8;
j=j+1;
j=j+2;

Option A. 8
Option B. 9
Option C. 7
Option D. 10
True Answer A

Explanation :

What would be value of j after the following is executed?

k=17;
j=6;
if (k < 10)
j=8;
j=j+1;
j=j+2;

Question No# : 17 out of 20



It is guaranteed that the while loop will be executed at least once.

Option A. TRUE
Option B. FALSE
Option C.
Option D.
True Answer B

Explanation :
No, Do while while loop will be executed at least once not while loop.

It is guaranteed that the while loop will be executed at least once.

Question No# : 18 out of 20

How many times the printf statement within the while loop will be executed?

int x=1; 
while(x=0) 
printf("hello");

Option A. 1
Option B. 0
Option C. infinite
Option D. 2
True Answer B

Explanation :

How many times the printf statement within the while loop will be executed?

int x=1; 
while(x=0) 
printf("hello");

Question No# : 19 out of 20



While loop is post tested loop.

Option A. TRUE
Option B. FALSE
Option C.
Option D.
True Answer B

Explanation :

While loop is post tested loop.

Question No# : 20 out of 20