# C PROGRAMS
C Quiz
➤ Identifiers & Data Types Quiz
➤ Octal Decimal & Hexadecimal
➤ Increment-Decrement Quiz
➤ Relational-Logical Quiz
➤ Arithmetic -Assignment Quiz
➤ Comma Operator Quiz
➤ Sizeof operator Quiz
➤ printf() Quiz Set-1
➤ printf() Quiz Set-2
➤ printf() Quiz Set-3
➤ printf() Quiz Set-4
➤ If statement Quiz in C
➤ If-else statement Quiz
If statement Quiz in C | The if-else statement in C is a selection statement. When dealing with selection statements, there are generally three versions: one-way, two-way, and multi-way.
One way decision statements do a particular thing or they do not. Two-way decision statements can do one thing or do another. Multi-way decision statements can do one of many different things depending on the value of an expression.
If you are finding it difficult to answer these questions then you should first learn these:- If-else statement in C, Programs on if-else in C
Note:- In C, 0 is the false and the non-zero value (both positive and negative) is true.
Q1) Find the output of the given C program.
#include<stdio.h>
int main()
{
if(0)
{
printf("x");
}
printf("y");
printf("z");
return 0;
}
a) xyz
b) Compile time error
c) yz
d) x
View Answer
Answer:- c) yzQ2) Find the output of the given C program.
#include<stdio.h>
int main()
{
int a;
a = 0, 1;
if(a)
{
printf("x");
printf("y");
}
printf("z");
return 0;
}
a) Compile time error
b) z
c) xy
d) xyz
View Answer
Answer:- b) zThe comma operator evaluates to its rightmost operand. So, a=0 and condition become false.
Q3) Find the output of the given C program.
#include<stdio.h>
int main()
{
if("false")
{
printf("x");
printf("y");
}
printf("z");
return 0;
}
a) z
b) Compile time error
c) xy
d) xyz
View Answer
Answer:- d) xyzThe “false” is a valid string so condition becomes true, and if block executed.
Q4) Find the output of the given C program.
#include<stdio.h>
int main()
{
if(5%5);
{
printf("x");
printf("y");
}
printf("z");
return 0;
}
a) z
b) xyz
c) xy
d) Compile time error
View Answer
Answer:- b) xyzNote that there is a semicolon after if(5%5), so if block completed. printf(“x”); and printf(“y”) is not the part of if block statement.
Q5) Find the output of the given C program.
#include<stdio.h>
int main()
{
if(0)
{
printf("x");
printf("y");
}
printf("z");
return 0;
}
a) z
b) xyz
c) Compile time error
d) xy
View Answer
Answer:- a) zQ6) Find the output of the given C program.
#include<stdio.h>
int main()
{
int a = 0, 1;
if(a)
{
printf("x");
printf("y");
}
printf("z");
return 0;
}
a) xy
b) Compile time error
c) xyz
d) z
View Answer
Answer:- b) Compile time errorCompile-time error due to int a=0,1; Here invalid declaration of variable.
Q7) Find the output of the given C program.
#include<stdio.h>
int main()
{
if('a')
{
printf("x");
printf("y");
}
printf("z");
return 0;
}
a) xy
b) xyz
c) z
d) Compile time error
View Answer
Answer:- b) xyzASCII value of ‘a’ is 97. So, the condition becomes true and display xy from the if block then from outside of if block z is displayed.
Q8) Find the output of the given C program.
#include<stdio.h>
int main()
{
if('a')
printf("x");
printf("y");
printf("z");
return 0;
}
a) xy
b) z
c) xyz
d) Compile time error
View Answer
Answer:- c) xyzQ9) Find the output of the given C program.
#include<stdio.h>
int main()
{
if()
{
printf("x");
printf("y");
}
printf("z");
return 0;
}
a) xyz
b) z
c) Compile time error
d) xy
View Answer
Answer:- c) Compile time errorCompile-time error; In C language if is a conditional statement and without condition, it can’t be executed.
Q10) Find the output of the given C program.
#include<stdio.h>
int main()
{
int a;
a = (0, 1);
if(a)
{
printf("x");
printf("y");
}
printf("z");
return 0;
}
a) Compile time error
b) z
c) xy
d) xyz
View Answer
Answer:- d) xyzHere () is used in a = (0,1); so expressions evaluated from left to right, Hence a=1; The if condition becomes true and if block executed.
Q11) Find the output of the given C program.
#include<stdio.h>
int main()
{
if("")
{
printf("x");
printf("y");
}
printf("z");
return 0;
}
a) xy
b) z
c) xyz
d) Compile time error
View Answer
Answer:- c) xyzThe empty string has a null character which value is other than zero so if statement becomes true.
Q12) Find the output of the given C program.
#include<stdio.h>
int main()
{
if(" ")
{
printf("x");
printf("y");
}
printf("z");
return 0;
}
a) xy
b) x
c) Compile time error
d) xyz
View Answer
Answer:- d) xyzThe value of string blank space is not zero so the condition of if block becomes true and displayed xy from if block. After that z is displayed from outside from the if block.
Q13) Find the output of the given C program.
#include<stdio.h>
int main()
{
if(0)
printf("x");
printf("y");
printf("z");
return 0;
}
a) xyz
b) x
c) Compile time error
d) yz
View Answer
Answer:- d) yzQ14) Find the output of the given C program.
#include<stdio.h>
int main()
{
int a=0;
if(a++)
{
printf("x");
printf("y");
}
printf("z");
return 0;
}
a) z
b) Compile time error
c) xyz
d) xy
View Answer
Answer:- a) zPostfix increment operator so first value assigned and then increment. Hence condition becomes false.
If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do you find anything incorrect? Let us know in the comments. Thank you!