Lec 11
Lec 11
I Semester 2008-09
Lecture 11
Types
1
Type conversion during assignment statement
2
type conversion in Assignment
i : a variable of type t1
E : an expression (of possibly different type).
1. Evaluate the expression E. Let val be its value and t2 be its type.
3
type casting
(t1)(E)
convert the type of (value of) E into t1.
Note : type cast has higher priority than any arithmetic operator.
4
type casting from wider to narrower range
5
type casting from narrower to wider
Information may get lost here also
Reason : the number of floating points possible using 32 bits float is less than the
number of integers represented by long.
6
type casting in asignment statements
i = (int)(x/y);
What is value of i ?
7
type casting in asignment statements
i = (int)(x/y);
the value of i is 1.
8
(Revisiting) Assigning literals to numeric variables
x = C;
x is a variable of numeric data type, C is a literal of numeric type.
9
Summary of steps to evaluate expression
1. parenthesize E
10
Summary of execute assignment statement
i = (t)(E)
3. follow the rule of type conversion (slide 3) and copy value into i.
11
For examples and practice problems on types and expression
evaluations, please go through the file practice.pdf available on
course website
12