E81 CSE 131 Lecture Notes - Lecture 1: Empty String, Decimal Mark, Master Sergeant
magentarat813 and 20 others unlocked
8
E81 CSE 131 Full Course Notes
Verified Note
8 documents
Document Summary
We can combine types in expressions where this makes sense. If two types participate in an expression, the result is usually of the more general type. The double type is more general than the int type. We can represent any int as a double. No way to represent 0. 5 as an int double radius = 2; Allowed, but we lose the data after the decimal point. The conversion requires the explicit cast, shown as (int) Result will just be 3 int avg = (2 + 3) / 2; The result is computed in integer arithmetic, so the value assigned to avg is 2 double avg = (2 + 3) / 2; The right-hand side is computed first, resulting in 2. Results in value 2. 0 for the avg double avg = (double) (2 + 3) / 2; (double) 1 / 2 + 2 / 3 + 3 / 4. It is overloaded from arithmetic for int and double types.