Multiple Choice Questions Till Switch Topic.
Question 1. What will be the output of the following
program
#include<stdio.h>
#include<conio.h>
main()
{
int i=1;
if(i<5)
printf(“%d”,i);
i++;
getch();
}
a. 1
b. 4
c. 5
d. None of these
Answer-a
Question 2. Determine the output of the following program
#include<stdio.h>
#include<conio.h>
main()
{
int n=5, f=1;
while(n>0)
f*=n--;
printf(“%d”,f);
getch();
}
a. 5
b. 1
c. 120
d. 2
Answer c
Question 3. Determine the output of the following program
#include <stdio.h>
#include<conio.h>
main()
{
int i=1;
while(i<5)
printf(“%d”,i);
i++;
getch();
}
a. 1
b. 4
c. 5
d. None of these
Answer d
Question 4. Determine the output of the following program
#include<stdio.h>
#include<conio.h>
main()
{
int i=100;
for(int j=1; j<=4;j++)
printf(“%d %d”,i,j);
getch();
}
a. 1001100210031004
b. 1001000100010001
c. 1001100110011001
d. 1001000100011
Answer a
Question 5. Determine the output of the following program
#include<stdio.h>
#include<conio.h>
int main ()
{
int x=5,y;
y=x++ + ++x +--x - x++;
printf(“%d %d”,x,y);
getch();
return 0;
}
1. 7 12
2. 12 7
3. 12 12
4. 7 10
Answer a
Question 6. Determine the output of the following program
#include<stdio.h>
#include<conio.h>
main()
{
int i=1;
for(;i<5;i++);
printf(“%d”,i++);
getch();
}
a. 1
b. 2
c. 4
d. 5
Answer d
Question 7. Determine the output of the following program
#include<stdio.h>
#include<conio.h>
main()
{
int i=1;
while(i<5)
printf(“%d”,i++);
getch();
}
a. 5
b. 4
c. 1234
d. 2345
Answer c
Question 8. Determine the output of the following program
#include<stdio.h>
#include<conio.h>
main()
{
int x=4+6*2-10/3;
printf(“%d”,++x+x++);
getch();
}
a. 28
b. 27
c. 26
d. 24
Answer a
Question 9. Analyze the code and find the output.
#include <stdio.h>
#include<conio.h>
int main()
{
int i = -3;
int k = i % 2;
printf("%d\n", k);
}
a) Compile time error
b) -1
c) 1
d) Implementation defined
Answer b
Question 10. What is the output of this C code?
#include <stdio.h>
int main()
{
int i = 3;
int l = i / -2;
int k = i % -2;
printf("%d %d\n", l, k);
return 0;
}
a) Compile time error
b) -1 1
c) 1 -1
d) Implementation defined
Answer b
Question 11. What is the value of x in this C code?
#include <stdio.h>
void main()
{
int x = 5 * 9 / 3 + 9;
}
a) 3.75
b) Depends on compiler
c) 24
d) 3
Answer c
Question 12. What is the output of this C code?
#include <stdio.h>
int main()
{
int x = 2, y = 0;
int z = y && (y |= 10);
printf("%d\n", z);
return 0;
}
a) 1
b) 0
c) Undefined behaviour due to order of evaluation
d) 2
Answer b
Question 13. What is the output of this C code?
#include <stdio.h>
int main()
{
int x = 2, y = 0;
int z = (y++) ? 2 : y == 1 && x;
printf("%d\n", z);
return 0;
}
a) 0
b) 1
c) 2
d)Undefined behavior
Answer b
Question 14. What is the output of this C code?
#include <stdio.h>
int main()
{
int x = 2, y = 0, l;
int z;
z = y = 1, l = x && y;
printf("%d\n", l);
return 0;
}
a) 0
b) 1
c) Undefined behaviour due to order of evaluation can
be different
d) Compilation error
Answer b
Question 15. What is the output of this 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
answer b
Question 16. What is the output of this C code?
#include <stdio.h>
int main()
{
int a = 10, b = 10;
if (a = 5)
b--;
printf("%d, %d", a, b--);
}
a) a = 10, b = 9
b) a = 10, b = 8
c) a = 5, b = 9
d) a = 5, b = 8
answer c
Question 17. What is the output of this 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
Answer b
Question 18. What is the output of this C code(When 1 is
entered)?
#include <stdio.h>
void main()
{
char *ch;
printf("enter a value btw 1 to 3:");
scanf("%s", ch);
switch (ch)
{
case "1":
printf("1");
break;
case "2":
printf("2");
break;
}
}
a) 1
b) Compile time error
c) 2
d) Run time error
answer b
Question 19. What is the output of this C code?
#include <stdio.h>
int main()
{
int x = 97;
switch (x)
{
case 'a':
printf("yes ");
break;
case 97:
printf("no\n");
break;
}
}
a) yes
b) yes no
c) Duplicate case value error
d) Character case value error
answer c
Question 20. What is the output of this C code?
#include <stdio.h>
int main()
{
float f = 1;
switch (f)
{
case 1.0:
printf("yes\n");
break;
default:
printf("default\n");
}
}
a) yes
b) yes default
c) Undefined behaviour
d) Compile time error
answer d