Example Of | Expression in Types | Numerical Example |
---|---|---|
decimal division | double / double ==> double | 10.0 / 4.0 = 2.5 |
integer division | int / int ==> int | 10 / 4 = 2 |
numeric promostion | int / double ==> double | 10 / 4.0 = 2.5 |
numeric promostion | double / int ==> double | 10.0 / 4 = 2.5 |
explicit casting | (int)double ==> int | (int)13.8 ==> 13 |
explicit casting | (double)int ==> double | (double)13 ==> 13.0 |
Attempted Assignment | Numerical Example | Compilation Error? | Due To |
---|---|---|---|
int = int; | int result = 3; | no error | same type |
double = double; | double result = 3.0; | no error | same type |
double = int; | double result = 3; | no error | numeric promotion |
int = double; | int result = 3.0; | ERROR | explicit cast needed |
Prior Declarations | Assignment | Type Execution of the Assignment | Actual Execution of the Assignment |
---|---|---|---|
int a; double x = 10.0 double y = 6.0 |
a = (int)x / (int)y; |
int = (int)double /
(int)double; int = int / int; int = int; |
a = (int)10.0 / (int)6.0; a = 10 / 6; a = 1; |
int a; double x = 10.0; double y = 6.0; |
a = (int)(x / y); |
int = (int)(double
/ double); int = (int) double; int = int |
a = (int)(10.0 / 6.0); a = (int)1.666667; a = 1; |
int a; int b = 3; double x = 35.5; double y = 10.4; |
a = (int)(y * b) % ((int)x % b) |
int = (int)(double * int)
% ((int)double % int); int = (int) double % ( int % int); int = int % int; int = int; |
a = (int)(10.4 * 3) % ((int)35.5 % 3); a = (int) 31.2 % ( 35 % 3); a = 31 % 2; a = 1; |
int a; int b = 3; double x = 35.5; double y = 10.4; |
a = (int)y * b % (int)x % b |
int = (int)double * int
% (int)double % int; int = int * int % int % int; int = int % int % int; int = int % int; int = int; |
a = (int)10.4 * 3 % (int)35.5. % 3; a = 10 * 3 % 35 % 3; a = 30 % 35 % 3; a = 30 % 3; a = 0; |