What is the data type of the following expression:
expr₁ ? expr₂ : expr₃
if expr₁ is of type float & expr₂ is of type int.
🎥 Video solution / Text Solution of this question is given below:
Solution:
In the **ternary operator** `(expr₁ ? expr₂ : expr₃)`,
the **data type of result** is the **common type** of `expr₂` and `expr₃`.
Here,
- `expr₁` → condition (float type, irrelevant for result type)
- `expr₂` → int
- `expr₃` → (not specified but implied same as expr₂ type logic)
When int and float are combined → **result type = float** (implicit type conversion).