CSADPRG_mod4_type_conversions

��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������original file
this is unedited

narrowing conversion

public static void main(String[] args) {  
    double x = 2.256891231231;  
    float y = (float) x;  
    System.out.printf("x = %.12f",x);  
    System.out.printf("\ny = %.12f",y);  
}

//output x = 2.256891231231 y = 2.256891250610

widening conversion

mixed-mode expressions

disadvantages of coercions

int a;  
  
float b, c, d;  
  
. . .  
  
d = b * a;

explicit type conversions

float x = 2.245;  
int y = (int) x;

errors in expressions during evaluation

int x = 2147483647 + 1;  
printf("%d",x);

/* output: 
main.c:13:25: warning: integer overflow in expression [-Woverflow] -2147483648
*/
public static void main(String[] args) {  
	    int x = 2/0;  
}

/* output
Exception in thread "main" java.lang.ArithmeticException: / by zero at Main.main(Main.java:12)   
*/