0% found this document useful (0 votes)
369 views4 pages

Quiz 3

The document contains 10 coding questions with multiple choice answers. The summaries are: 1) The code contains a do-while loop that calculates the maximum of three variables and decrements two counters until they reach zero, printing the final values of the counters. 2) The code contains a while loop that decrements two variables, increments one, calculates a sum, and prints values on each iteration until the condition is met. 3) The code contains a while loop that prints "Hello" on each iteration until the counter reaches zero, so it will print 11 times.

Uploaded by

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

Quiz 3

The document contains 10 coding questions with multiple choice answers. The summaries are: 1) The code contains a do-while loop that calculates the maximum of three variables and decrements two counters until they reach zero, printing the final values of the counters. 2) The code contains a while loop that decrements two variables, increments one, calculates a sum, and prints values on each iteration until the condition is met. 3) The code contains a while loop that prints "Hello" on each iteration until the counter reaches zero, so it will print 11 times.

Uploaded by

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

1. what will be the output of the following code?

#include<stdio.h>
int main() {
int c = 5, no = 10, x = 3, y = 4, z = 2, a;
do {
no /= c;
a = (x > y) ? ((x > z) ? x : z) : ((y > z) ? y : z);

} while (a-- && no--);

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


return 0;
}
Answers
1. 2 4
2. infinite loop
3. -1 3
4. no output

answer:3

2. What will be the output of the following code?


#include<stdio.h>
int main() {
int sum = 0;
unsigned int i = 20000;
unsigned int j = 500;
while (i-- / j++ > 1) {
j += j;
sum = sum + (i-- / j++);
printf("\n%d, %d, %dn", i, j, sum);
}
return 0;
}
Answers
1. 19999, 1002, 19n 19998, 2006, 28n 19997, 4014, 32n 19996, 8030, 34n 19995,
16062, 35n
2. Compile Time Error
3. 19997, 1004, 17n 19996, 2008, 29n 19995, 4016, 35n 19994, 8032, 32n 19993,
16064, 31n
4. 19998, 1003, 19n 19996, 2009, 28n 19994, 4021, 32n 19992, 8045, 34n 19990,
16093, 35n

Answer:4

3. #include <stdio.h>
int main()
{
int loop=10;
while(printf("Hello ") && loop--);
}
Answers
1. Hello Hello ... 10 times
2. Hello Hello ... 11 times
3. Hello
4. Error: lvalue required as increment operand

Answer:2
4. What will be the output of following code?

#include <stdio.h>
int main()
{
int i = 0, j = 0;
while ( i < 2)
{ l1 : i++;
while (j < 3)
{
printf("loop\n");
goto l1;
}
}
}
Answers
1. Loop Loop
2. Compilatiom Error
3. Loop Loop Loop Loop
4. Infinite Loop

Answer:4

5. What will be the output of following program ?


#include <stdio.h >
void main()
{
unsigned char var=0;
for(var=0; var ;var++)
{
printf("%d ",var);
}
}
Answers
1. 0 1 2 ... 255
2. No Output
3. 0 0 0 0 0 0 0 0 0 0 �.
4. 255 254 253 �.

Answer:2

6. What is the output of the following code?


#include<stdio.h>
void main()
{
int s=0;
while(s++<10)
{
if(s<4 && s<9)
continue;
printf(�\n%d\t�,s);
}
}
Answers
1. 1 2 3 1 0
2. 4 5 6 7 8 9
3. 4 5 6 7 8 9 10
4. 1 2 3 4 5 6 7 8 9
Answer:3

7. Output?
#include <stdio.h>
int main()
{
int c = 5, no = 10;
do {
no /= c;
} while(c--);

printf ("%dn", no);


return 0;
}
Answers
1. 1
2. Runtime Error
3. 0
4. Compiler Error

Answer:2

8. #include <stdio.h>
int main()
{
int i = 0, j = 0;
while (i<5,j<10)
{
i++;
j++;
}
printf("%d %d", i, j);
}
Answers
1. 5 5
2. syntax error
3. 5 10
4. 10 10

Answer:4

9. void main()
{
while(1){
if(printf("%d",printf("%d")))
break;
else
continue;
}
}
Answers
1. 1
2. Infinite loop
3. Garbage value
4. 0

Answer:3

10. What will be the output of the following code?


#include<stdio.h>
int main() {
int i = -3, j = 0;
while (i <= 3, j < 10) {
if (i >= 0)
break;
else {
i++;
j++;
}
printf("%d, %d\n", i, j);
continue;
}
printf("\nSunbeam");
return 0;
}
Answers
1. 2, 1 Sunbeam -1, 2 Sunbeam 0, 3 Sunbeam
2. -2, 1 -1, 2 0, 3 Sunbeam
3. Program will execute infinite no of times
4. Program will print sunbeam three times

Answer:2

You might also like