250+ TOP MCQs on Conditional Expressions and Answers

C Objective Questions on “Conditional Expressions”. One shall practice these Objective Questions to improve their C programming skills needed for various interviews (campus interviews, walkin interviews, company interviews), placements, entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C Programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our C Objective Questions come with detailed explanation of the answers which helps in better understanding of C concepts.

Here is a listing of C Objective Questions on “Conditional Expressions” along with answers, explanations and/or solutions:

1. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         int x = 2, y = 0;
  5.         int z = (y++) ? y == 1 && x : 0;
  6.         printf("%dn", z);
  7.         return 0;
  8.     }

a) 0
b) 1
c) Undefined behaviour
d) Compile time error
Answer: a
Clarification: None.

2. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         int x = 1;
  5.         int y =  x == 1 ? getchar(): 2;
  6.         printf("%dn", y);
  7.     }

a) Compile time error
b) Whatever character getchar function returns
c) Ascii value of character getchar function returns
d) 2
Answer: c
Clarification: None.

3. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         int x = 1;
  5.         short int i = 2;
  6.         float f = 3;
  7.         if (sizeof((x == 2) ? f : i) == sizeof(float))
  8.             printf("floatn");
  9.         else if (sizeof((x == 2) ? f : i) == sizeof(short int))
  10.             printf("short intn");
  11.     }

a) float
b) short int
c) Undefined behaviour
d) Compile time error
Answer: a
Clarification: None.

4. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         int a = 2;
  5.         int b = 0;
  6.         int y = (b == 0) ? a :(a > b) ? (b = 1): a;
  7.         printf("%dn", y);
  8.     }

a) Compile time error
b) 1
c) 2
d) Undefined behaviour
Answer: c
Clarification: None.

5. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         int y = 1, x = 0;
  5.         int l = (y++, x++) ? y : x;
  6.         printf("%dn", l);
  7.     }

a) 1
b) 2
c) Compile time error
d) Undefined behaviour
Answer: a
Clarification: None.

6. What will be the output of the following C code?

  1.     #include 
  2.     void main()
  3.     {
  4.         int k = 8;
  5.         int m = 7;
  6.         int z = k < m ? k++ : m++;
  7.         printf("%d", z);
  8.     }

a) 7
b) 8
c) Run time error
d) 15
Answer: a
Clarification: None.

7. What will be the output of the following C code?

  1.     #include 
  2.     void main()
  3.     {
  4.         int k = 8;
  5.         int m = 7;
  6.         int z = k < m ? k = m : m++;
  7.         printf("%d", z);
  8.     }

a) Run time error
b) 7
c) 8
d) Depends on compiler
Answer: b
Clarification: None.

8. What will be the output of the following C code?

  1.     #include 
  2.     void main()
  3.     {
  4.         1 < 2 ? return 1 : return 2;
  5.     }

a) returns 1
b) returns 2
c) Varies
d) Compile time error
Answer: d
Clarification: None.

Leave a Reply

Your email address will not be published. Required fields are marked *