This set of C Multiple Choice Questions & Answers (MCQs) focuses on “If-then-else Statements – 2”.
Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.
1. What will be the output of the following C code?
#include <stdio.h>
int main()
{
int x = 1;
if (x > 0)
printf("inside if\n");
else if (x > 0)
printf("inside elseif\n");
}
a) inside if
b) inside elseif
c)
inside if inside elseif
d) compile time error
View Answer
Explanation: None.
2. What will be the output of the following C code?
#include <stdio.h>
int main()
{
int x = 0;
if (x++)
printf("true\n");
else if (x == 1)
printf("false\n");
}
a) true
b) false
c) compile time error
d) undefined behaviour
View Answer
Explanation: None.
3. What will be the output of the following C code?
#include <stdio.h>
int main()
{
int x = 0;
if (x == 1)
if (x == 0)
printf("inside if\n");
else
printf("inside else if\n");
else
printf("inside else\n");
}
a) inside if
b) inside else if
c) inside else
d) compile time error
View Answer
Explanation: None.
4. What will be the output of the following C code?
#include <stdio.h>
int main()
{
int x = 0;
if (x == 0)
printf("true, ");
else if (x = 10)
printf("false, ");
printf("%d\n", x);
}
a) false, 0
b) true, 0
c) true, 10
d) compile time error
View Answer
Explanation: None.
5. What will be the output of the following C code?
#include <stdio.h>
int main()
{
int x = 0;
if (x == 1)
if (x >= 0)
printf("true\n");
else
printf("false\n");
}
a) true
b) false
c) Depends on the compiler
d) No print statement
View Answer
Explanation: None.
6. The C statement “”if (a == 1 || b == 2) {}”” can be re-written as ___________
a)
if (a == 1) if (b == 2){}
b)
if (a == 1){} if (b == 2){}
c)
if (a == 1){} else if (b == 2){}
d) none of the mentioned
View Answer
Explanation: None.
7. Which of the following is an invalid if-else statement?
a) if (if (a == 1)){}
b) if (func1 (a)){}
c) if (a){}
d) if ((char) a){}
View Answer
Explanation: None.
8. What will be the output of the following C code?
#include <stdio.h>
int main()
{
int a = 1;
if (a--)
printf("True");
if (a++)
printf("False");
}
a) True
b) False
c) True False
d) No Output
View Answer
Explanation: None.
9. What will be the output of the following C code?
#include <stdio.h>
int main()
{
int a = 1;
if (a)
printf("All is Well ");
printf("I am Well\n");
else
printf("I am not a River\n");
}
a) Output will be All is Well I am Well
b) Output will be I am Well I am not a River
c) Output will be I am Well
d) Compile time errors during compilation
View Answer
Explanation: None.
10. What will be the output of the following C code?
#include <stdio.h>
int main()
{
if (printf("%d", printf(")))
printf("We are Happy");
else if (printf("1"))
printf("We are Sad");
}
a) 0We are Happy
b) 1We are Happy
c) 1We are Sad
d) compile time error
View Answer
Explanation: None.
Sanfoundry Global Education & Learning Series – C Programming Language.
To practice all areas of C language, here is complete set of 1000+ Multiple Choice Questions and Answers.
If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]
- Apply for Computer Science Internship
- Practice BCA MCQs
- Practice Computer Science MCQs
- Check C Books
- Check Computer Science Books