0% found this document useful (0 votes)
11 views

Assignment 16 Forloop Ans

This document contains 20 multiple choice questions about for loops and their syntax and usage in C programming. The questions cover topics like valid syntax for different parts of for loops, output of code samples using for loops, and terminology related to loops and their termination conditions.

Uploaded by

Yash rai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Assignment 16 Forloop Ans

This document contains 20 multiple choice questions about for loops and their syntax and usage in C programming. The questions cover topics like valid syntax for different parts of for loops, output of code samples using for loops, and terminology related to loops and their termination conditions.

Uploaded by

Yash rai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Assignment of objective questions

1. Is the following syntax of for loop is correct?


for( ; i <= 10; i++)
{
....
....
}

a. Yes
b. No
c. Syntax Error
d. Runtime Error

Answer - a. Yes

2. Is the following syntax of for loop is correct?


for( ; i <= 10; )
{
....
i++;
}

a. Yes
b. No
c. Syntax Error
d. Runtime Error

Answer - a. Yes

3. Is the following syntax of the "for" loop is correct?


for( ; ; )
{
i <= 10;
i++;
}

a. Yes
b. No
c. Syntax Error
d. Runtime Error

Answer - d. Runtime Error

4. Is the following syntax of for loop is correct?


for( ; i <= 10; i++);
{
....
....
}

a. Yes
b. No
c. Syntax Error
d. Runtime Error

Answer - a. Yes

5. The following syntax of for loop is also known as...


for( ; i <= 10; i++);
{
....
....
}
a. Mature Loop
b. Forbidden Loop
c. Null Loop
d. Infinite Loop

Answer - c. Null Loop

6. The test condition given in the for loop is also known as...

a. Necessary Condition
b. Parent Condition
c. Root Condition
d. None of the above

Answer - b. Parent Condition

7. The loop terminated by its given parent condition is known as...

a. Mature Termination
b. Immature Termination
c. False Termination
d. None of the above

Answer - a. Mature Termination

8. The loop terminated by break present inside the body of the for loop is known
as...

a. Mature Termination
b. Immature Termination
c. Pre-Mature Termination
d. None of the above

Answer - c. Pre-Mature Termination

9. Can we use the keyword continue outside the loop(or without using it inside a
loop)?
a. Yes
b. No, ERROR! MISPLACED CONTINUE! (In Turbo)
c. Yes, only in Turbo
d. Yes, only in modern compiler

Answer - b. No, ERROR! MISPLACED CONTINUE! (In Turbo)

10. If we use continue within the loop, it transfers the control to...

a. Statement Part
b. Parent Condition Part
c. Current Condition Part
d. First Line of the loop body

Answer - a. Statement Part

11. If we use continue within the for loop then the termination will be...

a. Mature Termination
b. Immature Termination
c. Pre-Mature Termination
d. None of the above

Answer - a. Mature Termination

12. What is the output of the following code?


main()
{
int a = 0, k = 1;
while(a < 10)
{
k++;
a++;
}
printf("%d %d", a, k);
}

a. 9 10
b. 10 10
c. 10 11
d. 9 9

Answer - c. 10 11

13. What is the output of the following program?


main()
{
int a = 0, k = 10;
while(a < k)
{
k = k - a;
a++;
}
printf("%d %d", a, k);
}

a. 3 7
b. 4 4
c. 9 10
d. 4 10

Answer - b. 4 4

14. Find the output of the following program


main()
{
int k = 1, x = 3, y = 4, a;
for(a = y; a > 0; a--)
k = k * x;
printf("%d", k);
}

a. 81
b. 729
c. 27
d. 0

Answer - a. 81

15. Find the output of the following program


main()
{
int a = 0, k = 10;
while(1)
{
k = k + a;
a = k - a;
k = k - a;
if(a < k)
break;
else
a++;
k = k - 2;
}
printf("%d %d", a ,k);
}

a. -2 11
b. 4 4
c. 0 11
d. 2 11

Answer - a. -2 11

16. Find the output of the following program


main()
{
int a = 0;
while(a < 10)
{
if(a % 3 == 0)
{
a++;
continue;
}
if(a % 4 != 0)
a = a + 2;
if(a % 5 != 0)
{
a++;
break;
}
}
printf("%d", a);
}

a. 0
b. 2
c. 4
d. 5

Answer - c. 4

17. Find the output of the following program


main()
{
int a = 2;
while(a >= -5 && a <= 5)
{
switch(a)
{
case -1:
a = a + 2;
case 2:
a = a - 3;
break;
case 3:
a = a + 4;
break;
default:
a = a - 5;
}
printf("%d", a);
}
}

a. -1 2 -7
b. -1 -2 -7
c. 1 -2 -7
d. None of these

Answer - b. -1 -2 -7

18. Find the output of the following program


main()
{
int a;
for(a = 2; a <= 10; a++)
{
switch(a % 3)
{
case 0:
a = a + 2;
case 1:
a = a - 3;
break;
case 2:
a = a + 4;
break;
default:
a = a - 5;
}
printf("%d", a);
}
}
a. 6 4 9 7 12
b. 6 4 9 7
c. 6 4 9 7 10
d. ERROR!

Answer - a. 6 4 9 7 12

19. Can we give multiple initializations and


statements to the for loop?

a. Yes, should be separated with ","


b. No, only allowed in modern compiler
c. Syntax Error!
d. Runtime Error!

Answer - a. Yes, it is a valid Syntax

20. Can we give multiple test conditions to the for loop?

a. Yes, should be separated from the logical operator


b. No, only allowed in modern compiler
c. Syntax Error!
d. Runtime Error!

Answer - a. Yes, should be separated from the logical operator

You might also like