Expressions, Operator Precedence, MATHS w1 Flashcards
operator for addition
+
operator for subtraction
-
operator for multiplication
*
operator for division
/
operator for modulus
%
when we divide integers do we get doubles or integers
integers
when doubles are divided do we get doubles or integers
doubles
what does modulus give us
what is the remainder on division eg 7%3=1
what is the addition component assignment operator
+=
what is += equivalent to
variable=variable+expression
eg, calculate {result += 15/3}, assuming result is 7
12
order of precedence
unary prefix unary postfix multiplicative additive relational equality conditional assignment
what are unary prefixes
++ –
what are unary postfixes
+ - (as in negative and positive numbers)
what is involved in the multiplicative type
- / %
what is involved in the additive type
+ - (sums)
what is involved in the relational types
< <= > >=
what is involved in teh equality type
== !=
what is involved in the assignment operators type
= += -= *= /= %=
what order will this sum be calculated?
int result = 12 + 6 / -4 * 5 - 3
- negative 4
- 6/-4 =-1.5
- (6/-4)*5 =-7.5
- 12+(-7.5) =4.5
- 4.5 - 3 =1.5
- =1.5
associativity of multiplicative
left to right
associativity of additive
left to right
associativity of relational
right to left
associativity of assignment
right to left