Condition MCQ


Q 1) Choose a C Conditional Operator from the list.
  1. ?:
  2. :?
  3. :<
  4. <:

Answer:- (A).
Explanations :?: = Question Mark Colon is also called C Ternary Operator.
Q2) What is the other name for C Language ?: Question Mark Colon Operator.?
  1. Comparison Operator
  2. If-Else Operatorg
  3. Binary Operator
  4. Ternary Operator

Answer:- (C).
Q3) Choose a syntax for C Ternary Operator from the list.
  1. condition ? expression1 : expression2
  2. condition : expression1 ? expression2
  3. condition ? expression1 < expression2
  4. condition < expression1 ? expression2

Answer:- (A).
Explanations :If the condition is true, expression 1 is evaluated. If the condition is false, expression 2 is evaluated.
Q4) What is the output of the C statement.?
 int main()
{
    int a=0;
    a = 5<2 ? 4 : 3;
    printf("%d",a);

    return 0;
}
  1. 4
  2. 3
  3. 5
  4. 2

Answer:- (B).
Explanations :5<2 is false. So 3 will be picked and assigned to the variable a.
Q5) What is the output of C Program.?
 int main()
{
    int a=0;
    a = printf("4");
    printf("%d",a);

    return 0;
}
  1. 04
  2. compiler error
  3. 40
  4. 41

Answer:- (D).
Explanations :a = printf("4"); First printf prints 4. printf() returns 1. Now the variable a=1; So 1 is printed next.
Q6) What is the output of the C Program.?
 int main()
{
    int a=0;
    a = 5>2 ? printf("4"): 3;
    printf("%d",a);

    return 0;
}
  1. compiler error
  2. 14
  3. 41
  4. 0

Answer:- (C).
Explanations :5>2 is true. So expression1 i.e printf("4) is executed printing 4. Function printf() returns 1. So a value is 1.
Q7) What is the output of the C Program.?
int main(); 
{
    int a=0;
    a = (5>2) ? : 8;
    printf("%d",a);

    return 0;
}
  1. 1
  2. 0
  3. 8
  4. compiler error

Answer:- (A).
Explanations :expression1 = empty
expression2 = 8
If no expression is specified, it will be treated as 1.
Q8) What is the output of C Program.?
int main(); 
{
    int a=0, b;
    a = (5>2) ? b=6: b=8;
    printf("%d %d",a, b);

    return 0;
}
  1. 6 6
  2. 0 6
  3. 0 8
  4. compiler errore

Answer:- (D).
Explanations :Compiler error. a = (5>2) ? b=6: b=8; should be written as a = (5>2) ? b=6: (b=8); main.c: In function ‘main’: main.c:14:23: error: lvalue required as left operand of assignment a = (5>2) ? b=6: b=8;
Q9) Choose a correct statement regarding C Comparison Operators.
#include <stdio.h>
int main()
{
int i;
for(i=0; i < 5, i++)
{
int a = i;
}
printf("%d",a);
return 0;
}
  1. (x == y) Is x really equal to y. (x != y) Is x not equal to y.
  2. (x < y) Is x less than y (x > y) Is x greater than y
  3. (x <= y) Is x less than or equal to y. (x >= y) Is x greater than or equal to y
  4. All the above

Answer:- (D).
Q10) Choose a statement to use C If Else statement.
  1. else if is compulsory to use with if statement.
  2. else is compulsory to use with if statement.
  3. else or else if is optional with if statement.
  4. None of the above

Answer:- (C)