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?
-
#include
-
void main()
-
{
-
int k = 8;
-
int m = 7;
-
k < m ? k++ : m = k;
-
printf("%d", k);
-
}
a) 7
b) 8
c) Compile time error
d) Run time error
Answer: c
Clarification: None.
2. What will be the output of the following C code?
-
#include
-
void main()
-
{
-
int k = 8;
-
int m = 7;
-
k < m ? k = k + 1 : m = m + 1;
-
printf("%d", k);
-
}
a) Compile time error
b) 9
c) 8
d) Run time error
Answer: a
Clarification: None.
3. What will be the final values of a and c in the following C statement? (Initial values: a = 2, c = 1)
a) a = 0, c = 0;
b) a = 2, c = 2;
c) a = 2, c = 2;
d) a = 1, c = 2;
Answer: a
Clarification: None.
4. What will be the data type of the following expression? (Initial data type: a = int, var1 = double, var2 = float)
expression (a < 50)? var1 : var2;
a) int
b) float
c) double
d) Cannot be determined
Answer: c
Clarification: None.
5. Which expression has to be present in the following?
exp1 ? exp2 : exp3;
a) exp1
b) exp2
c) exp3
d) all of the mentioned
Answer: d
Clarification: None.
6. What will be the final value of c in the following C code snippet? (Initial values: a = 1, b = 2, c = 1)
a) Syntax Error
b) c = 1
c) c = 2
d) c = 3
Answer: c
Clarification: None.
7. The following C code can be rewritten as _______
a)
if (!n)c = b; else c = a;
b)
if (n <;= 0)c = b; else c = a;
c)
if (n > 0)c = a; else c = b;
d) All of the mentioned
Answer: a
Clarification: None.