C Programming Questions and Answers – If-then-else Statements – 2
C Programming Questions and Answers – If-then-else Statements – 2
1. What is the output of this 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
2. What is the output of this 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
3. What is the output of this 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
4. What is the output of this 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
5. What is the output of this 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
6. if (a == 1||b == 2){} can be 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
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
8. What is the output of this 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
9. Comment on the output of this 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
10. What is the output of this 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
For more Visit the Link:
Computer Science MCQ All Topic C programming MCQ All Topic