If Else Statement In C: MCQs On If Else in C Language
If Else Statement In C. Multiple Choice Questions on If – Else – Then Statements
If Else Statement In C
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){}
a) if (if (a == 1)){}
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
d) compile time error
What will be the output ?
#include <stdio.h>
void main()
{
int x = 5;
if (x < 1)
printf(“hello”);
if (x == 5)
printf(“hi”);
else
printf(“no”);
}
a) hi
b) hello
c) no
d) error
a) hi
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
d) Compile time errors during compilation
If Else Statement In C
What will be the output of the following program ?
#include <stdio.h>
int x;
void main()
{
if (x)
printf(“hi”);
else
printf(“how are u”);
}
a) hi
b) how are you
c) compile time error
d) error
b) how are you
What will be the output of the following 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
What will be the output of the program ?
#include <stdio.h>
void main()
{
int x = 5;
if (true);
printf(“hello”);
}
a) It will display hello
b) It will throw an error
c) Nothing will be displayed
d) Compiler dependent
b) It will throw an error
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 Answerd) none of the mentioned
If Else Statement In C
What will be the output ?
#include <stdio.h>
void main()
{
int x = 0;
if (x == 0)
printf(“hi”);
else
printf(“how are u”);
printf(“hello”);
}
a) hi
b) how are you
c) hello
d) hihello
d) hihello
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
d) No print statement
What will be the output of the following program ?
#include <stdio.h>
void main()
{
int x = 5;
if (x < 1);
printf(“Hello”);
}
a) Nothing
b) Run time error
c) Hello
d) Varies
c) Hello
What will be the output of the following 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
b) true, 0
If Else Statement In C
What will be the output of the program ?
INPUT = 1
#include <stdio.h>
void main()
{
double ch;
printf(“enter a value between 1 to 2:”);
scanf(“%lf”, &ch);
switch (ch)
{
case 1:
printf(“1”);
break;
case 2:
printf(“2”);
break;
}
}
a) Compile time error
b) 1
c) 2
d) Varies
a) Compile time error
What will be the output ?
#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
c) inside else
What will be the output of the following c code ?
INPUT = 1
#include <stdio.h>
void main()
{
char *ch;
printf(“enter a value between 1 to 3:”);
scanf(“%s”, ch);
switch (ch)
{
case “1”:
printf(“1”);
break;
case “2”:
printf(“2”);
break;
}
}
a) 1
b) 2
c) Compile time error
d) No Compile time error
c) Compile time error
What will be the output of the following program ?
#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
b) false
If Else Statement In C
What will be the output of the following c code ?
INPUT = 1
#include <stdio.h>
void main()
{
int ch;
printf(“enter a value between 1 to 2:”);
scanf(“%d”, &ch);
switch (ch)
{
case 1:
printf(“1\n”);
default:
printf(“2\n”);
}
}
a) 1
b) 2
c) 1 2
d) Run time error
c) 1 2
What will be the output of the following C code ?
INPUT = 2
#include <stdio.h>
void main()
{
int ch;
printf(“enter a value between 1 to 2:”);
scanf(“%d”, &ch);
switch (ch)
{
case 1:
printf(“1\n”);
break;
printf(“Hi”);
default:
printf(“2\n”);
}
}
a) 1
b) Hi 2
c) Run time error
d) 2
d) 2
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 Answera) inside if
What will be the output of the following C code ?
INPUT = 1
#include <stdio.h>
void main()
{
int ch;
printf(“enter a value between 1 to 2:”);
scanf(“%d”, &ch);
switch (ch, ch + 1)
{
case 1:
printf(“1\n”);
break;
case 2:
printf(“2”);
break;
}
}
a) 1
b) 2
c) 3
d) Run time error
b) 2
…
If Else Statement In C: MCQs On If Else in C LanguageRead More »