Discussion
In C programming language, if the first and the second operands of operator + are of types int and float, respectively, the result will be of type
Answer: B
Correct answer: float
The usual arithmetic conversions apply: when the operands of a binary operator have different types, the one of lower rank is converted to the type of the other before the operation, and the result has that common type.
Here int is converted to float, so the addition is performed in floating point and the result is float. The rule is why integer division is such a common source of surprise - 1/2 is 0 because both operands are int, whereas 1/2.0 is 0.5.
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development