CSADPRG_mod5_expressions_assignment_statements

original file

this is unedited

arithmetic expressions

design issues

operator precedence vs operator associativity

operator precedence: typical precedence levels

_attachments/Pasted image 20240615002036.png

operator associativity: left and right associativity

conditional expressions

if (count == 0)
	average = 0
else
	average = sum / count

// when using a ternary operator
average = (count == 0)? 0: sum / count

operand evaluation order

functional side effects

a = 10;
b = a + fun(&a);

int a = 5;
int fun1() {
	a = 17;
	return 3;
}
void main() {
	a = a + fun1();
}

solution to side effects

overloading

narrowing and widening conversion

mixed-mode expressions

explicit type conversions

float x = 2.222
int y = (int) x

errors in expressions

relational expressions

_attachments/Pasted image 20240615003123.png

boolean expressions

_attachments/Pasted image 20240615003157.png

short circuit evaluation

assignment statements

multiple assignments

conditional targets

compound assignment operators

unary assignment operator

assignment as an expression

assignment in functional PL

mixed mode assignment

does the type of the expression have to be the same as the type of the variable being assigned, or can coercion be used in some cases of type mismatch?

_attachments/Pasted image 20240615004121.png