If Else MCQ Ans
If Else MCQ Ans
Answer: a
Answer: b
Answer: b
4. What will be the output of the following C code?
1. #include <stdio.h>
2. void main()
3. {
4. int x = 0;
5. if (x == 0)
6. printf("hi");
7. else
8. printf("how are u");
9. printf("hello");
10. }
a) hi
b) how are you
c) hello
d) hihello
Answer: d
Answer: c
6. What will be the output of the following C code? (Assuming that we have entered the value 1 in the standard
input)
1. #include <stdio.h>
2. void main()
3. {
4. double ch;
5. printf("enter a value between 1 to 2:");
6. scanf("%lf", &ch);
7. switch (ch)
8. {
9. case 1:
10. printf("1");
11. break;
12. case 2:
13. printf("2");
14. break;
15. }
16. }
a) Compile time error
b) 1
c) 2
d) Varies
Answer: a
7. What will be the output of the following C code? (Assuming that we have entered the value 1 in the standard
input)
1. #include <stdio.h>
2. void main()
3. {
4. char *ch;
5. printf("enter a value between 1 to 3:");
6. scanf("%s", ch);
7. switch (ch)
8. {
9. case "1":
10. printf("1");
11. break;
12. case "2":
13. printf("2");
14. break;
15. }
16. }
a) 1
b) 2
c) Compile time error
d) No Compile time error
Answer: c
8. What will be the output of the following C code? (Assuming that we have entered the value 1 in the standard
input)
1. #include <stdio.h>
2. void main()
3. {
4. int ch;
5. printf("enter a value between 1 to 2:");
6. scanf("%d", &ch);
7. switch (ch)
8. {
9. case 1:
10. printf("1\n");
11. default:
12. printf("2\n");
13. }
14. }
a) 1
b) 2
c) 1 2
d) Run time error
Answer: c
9. What will be the output of the following C code? (Assuming that we have entered the value 2 in the standard
input)
1. #include <stdio.h>
2. void main()
3. {
4. int ch;
5. printf("enter a value between 1 to 2:");
6. scanf("%d", &ch);
7. switch (ch)
8. {
9. case 1:
10. printf("1\n");
11. break;
12. printf("Hi");
13. default:
14. printf("2\n");
15. }
16. }
a) 1
b) Hi 2
c) Run time error
d) 2
Answer: d
10. What will be the output of the following C code? (Assuming that we have entered the value 1 in the standard
input)
1. #include <stdio.h>
2. void main()
3. {
4. int ch;
5. printf("enter a value between 1 to 2:");
6. scanf("%d", &ch);
7. switch (ch, ch + 1)
8. {
9. case 1:
10. printf("1\n");
11. break;
12. case 2:
13. printf("2");
14. break;
15. }
16. }
a) 1
b) 2
c) 3
d) Run time error
Answer: b
1. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. int x = 1;
5. if (x > 0)
6. printf("inside if\n");
7. else if (x > 0)
8. printf("inside elseif\n");
9. }
a) inside if
b) inside elseif
c)
inside if
inside elseif
d) compile time error
Answer: a
Answer: b
Answer: c
Answer: b
Answer: d
Answer: d
Answer: a
Answer: a
Answer: d
Answer: d