A Place for Latest Exam wise Questions, Videos, Previous Year Papers, Study Stuff for MCA Examinations - NIMCET
Previous Year Question (PYQs)
2
What is the data type of the following expression:
expr₁ ? expr₂ : expr₃
if expr₁ is of type float & expr₂ is of type int.
Solution
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).
Online Test Series, Information About Examination, Syllabus, Notification and More.