Log In Register

Units


Conditional Expressions - Questions and Answers

 

Practice these Conditional Expressions under C Programming walk-in interview Questions/ examination questions with best tricks and short cuts with solution. Student (candidate) who want to crack the walk in interview, competitive exams and want to find short cuts and tricks to solve questions on Conditional Expressions for following purpose.


– Anyone who is wishing to increase their perfect knowledge of Conditional Expressions of C Programming.
– Anyone who is preparing for aptitude test and increase his in depth aptitude knowledge C Programming specifically Conditional Expressions.
– Anyone who is preparing for interviews (competitive examinations, govt examinations and bank examinations, off-campus or on campus interviews, walk-in interview and company interviews) having questions on Conditional Expressions under C Programming.

– Anyone who is preparing for aptitude test or competitive exam or entrance exam.
– Anyone who is preparing for entrance examinations and other competitive examinations.
– All Experienced, Freshers and Students.

Here is list of Questions and Answers covering all key area of  Conditional Expressions topic of C Programming:

 

1.

What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int y = 1, x = 0;
  5.         int l = (y++, x++) ? y : x;
  6.         printf("%d\n", l);
  7.     }

Answer: Option D

Explanation:

2.

What is the output of this C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int x = 1;
  5.         int y =  x == 1 ? getchar(): 2;
  6.         printf("%d\n", y);
  7.     }

Answer: Option B

Explanation:

3.

What is the output of this C code?

  1.     #include <stdio.h>
  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("%d\n", y);
  8.     }

Answer: Option B

Explanation:

4.

What will be the data type of the expression (a < 50) ? var1 : var2;
    provided a = int, var1 = double, var2 = float

Answer: Option B

Explanation:

5.

What is the output of this C code?

  1.     #include <stdio.h>
  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("float\n");
  9.         else if (sizeof((x == 2) ? f : i) == sizeof(short int))
  10.             printf("short int\n");
  11.     }

Answer: Option D

Explanation:

6.

The code snippet below produces

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

Answer: Option A

Explanation:

7.

What is the output of this C code?

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

Answer: Option D

Explanation:

8.

Which expression has to be present in the following?
    exp1 ? exp2 : exp3;

Answer: Option D

Explanation:

9.

The output of the code below is

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

Answer: Option D

Explanation:

10.

For initialization a = 2, c = 1 the value of a and c after this code will be
     c = (c) ? a = 0 : 2;

Answer: Option D

Explanation:

11.

Value of c after the following expression (initializations a = 1, b = 2, c = 1):
     c += (-c) ? a : b;

Answer: Option B

Explanation:

12.

Comment on the following expression?
    c = (n) ? a : b; can be rewritten as

Answer: Option C

Explanation:

13.

What is the output of this C code?

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

Answer: Option C

Explanation:

14.

The output of the code below is

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

Answer: Option B

Explanation:

15.

Comment on the output of this C code?

  1.     #include <stdio.h>
  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.     }

Answer: Option A

Explanation: