github

Made bySaurav Hathi

MCQ Test C/C++: Conditions

Q1:

What will be the output of below C program?

#include <stdio.h>

int main()

{

float f1 = 0.1;

if (f1 == 0.1)

printf("Equal\n");

else

printf("Not equal\n");

}

Tags:
Section:
Core Programming
Options:
Q2:

What will be the output of below C program?

#include <stdio.h>

int main()

{

int i = 0, j = 0;

if (i && (j = i + 10)){}

printf("%d",j);

}

Tags:
Section:
Core Programming
Options:
Q3:

What is the output of this C code?

#include <stdio.h>

int main()

{

int i = 1;

if (i++ && (i == 1))

printf("Yes\n");

else

printf("No\n");

}

Tags:
Section:
Core Programming
Options:
Q4:

What will be the output of this C program?

#include <stdio.h>

int main()

{

int a = 10;

if (a == a--)

printf("TRUE 1\t");

a = 10;

if (a == --a)

printf("TRUE 2\t");

}

Tags:
Section:
Core Programming
Options:
Q5:

What is the output of this C code?

#include <stdio.h>

int main()

{

unsigned int i = 23;

signed char c = -23;

if (i > c)

printf("Yes\n");

else if (i < c)

printf("No\n");

}

Tags:
Section:
Core Programming
Options:
Q6:

What is the output of this C code?

#include <stdio.h>

int main()

{

1 < 2 ? return 1: return 2;

}

Tags:
Section:
Core Programming
Options:
Q7:

What is the output of this C code?

#include <stdio.h>

int main()

{

int x = 1;

int y =  x == 1 ? getchar(): 2;

printf("%d\n", y);

}

Tags:
Section:
Core Programming
Options:
Q8:

What is the output of this C code?

#include <stdio.h>

int main()

{

int x = 1;

short int i = 2;

float f = 3;

if (sizeof((x == 2) ? f : i) == sizeof(float))

printf("float\n");

else if (sizeof((x == 2) ? f : i) == sizeof(short int))

printf("short int\n");

}

Tags:
Section:
Core Programming
Options:
Q9:

What is the output of this C code?

#include <stdio.h>

int main()

{

int k = 8;

int m = 7;

int z = k < m ? k++ : m++;

printf("%d", z);

}

Tags:
Section:
Core Programming
Options:
Q10:

What is the output of this C code?

#include <stdio.h>

int main()

{

int x = 2, y = 0;

int z = (y++) ? 2 : y == 1 && x;

printf("%d\n", z);

return 0;

}

Tags:
Section:
Core Programming
Options:
Q11:

The output of the C code below is:-

#include <stdio.h>

int main()

{

int x = 5;

if (x < 1)

printf("hello");

if (x == 5)

printf("hi");

else

printf("no");

}

Tags:
Section:
Core Programming
Options:
Q12:

What is the output of this C code?

#include <stdio.h>

int main()

{

int x = 0;

if (x == 0)

printf("hi");

else

printf("how are u");

printf("hello");

}

Tags:
Section:
Core Programming
Options:
Q13:

What will be the output of the C code below when 1 is entered as input?

#include <stdio.h>

int main()

{

double ch;

printf("enter a value btw 1 to 2:");

scanf("%lf", &ch);

switch (ch)

{

case 1:

printf("1");

break;

case 2:

printf("2");

break;

}

}

Tags:
Section:
Core Programming
Options:
Q14:

What will be the output of the C code below when 2 is entered as input?

#include <stdio.h>

int main()

{

int ch;

printf("enter a value btw 1 to 2:");

scanf("%d", &ch);

switch (ch)

{

case 1:

printf("1\n");

break;

printf("Hi");

default:

printf("2\n");

}

}

Tags:
Section:
Core Programming
Options:
Q15:

What will be the output of the C code below when 1 is entered as input?

#include <stdio.h>

int main()

{

int ch;

printf("enter a value btw 1 to 2:");

scanf("%d", &ch);

switch (ch, ch + 1)

{

case 1:

printf("1\n");

break;

case 2:

printf("2");

break;

}

}

Tags:
Section:
Core Programming
Options:
Q16:

What is the output of this C code when 3 is entered?

#include <stdio.h>

int main()

{

int ch;

printf("enter a value btw 1 to 2:");

scanf("%d", &ch);

switch (ch,ch+1)

{

case 1:

printf("1\n");

break;

printf("hi");

default:

printf("2\n");

}

}

Tags:
Section:
Core Programming
Options:
Q17:

What is the output of this C code?

#include <stdio.h>

int main()

{

int a = 1, b = 1;

switch (a)

{

case a*b:

printf("yes ");

case a-b:

printf("no\n");

break;

}

}

Tags:
Section:
Core Programming
Options:
Q18:

What will be the output of below C program?

#include <stdio.h>

int main()

{

int x = 97;

switch (x)

{

case 'a':

printf("yes ");

break;

case 97:

printf("no\n");

break;

}

}

Tags:
Section:
Core Programming
Options:
Q19:

What is the output of this C code?

#include <stdio.h>

int main()

{

float f = 1;

switch (f)

{

case 1.0:

printf("yes\n");

break;

default:

printf("default\n");

}

}

Tags:
Section:
Core Programming
Options:
Q20:

What is the output of this C code?

#include <stdio.h>

int main()

{

int i = 0;

for (i = 0;i < 5; i++)

if (i < 4)

{

printf("Hello");

break;

}

}

Tags:
Section:
Core Programming
Options:
Q21:

The output of the C code below is

#include <stdio.h>

int main()

{

int i = 0;

if (i == 0)

{

goto label;

}

label: printf("Hello");

}

Tags:
Section:
Core Programming
Options:
Q22:

What will be the output of below C program?

#include <stdio.h>

int main()

{

int i = 0, k;

label: printf("%d", i);

if (i == 0)

goto label;

}

Tags:
Section:
Core Programming
Options: