Advanced Expressions -------------------- I am going to start off with some simple expressions and slowly make them harder and more complicated. Here goes for values: a = 10 and b = 11 a 10 Answer = 10 The next one uses some basic mathematical operations: a + 5 10 + 5 15 Answer = 15 Let us add some more operations: a - b * 10 / 10 10 - 11 * 10 / 10 10 - 110 / 10 10 - 11 -1 Answer = -1 Let us add parenthesis and modulus: a % (b - 5) 10 % (11 - 5) 10 % 6 4 Answer = 4 Next let us try adding conditions: a + b == b - 1 10 + 11 == 11 - 1 21 == 10 0 since False Answer = 0 Now let's get really complicated: a = b == 5 - a + 6 a = 11 == 5 - 10 + 6 (note the leftmost variable of an assignment does gets assigned a value) 11 == -5 + 6 11 == 1 0 Answer = 0 Conditional Expressions ----------------------- Moving on, let us head in a different direction. Let's say we have an if_else statement liek this: if( z == 20 ) y = 10; else y = 30; This whole statement may be reduce to a one line statement like this: y = (z == 20? 10:30); This is equivalent to the above! It first tests the "z == 20" condition. If it is true, then the first element after the question mark gets assigned to the variable y. Otherwise the second value is assigned. Casts ----- These are not something you wear when you break a bone, these are a means to change the type of variable into another type. For example: int a = 10; float b = 20.5; If you wanted to add these two, it may be suggested that you cast the integer into a float when adding to be sure it doesn't round the floating point number to an integer. This may be done like this: float sum; sum = (float) a + b; The (float) is a cast. You could also go the other way: int sum; sum = a + (int) b; Or you could do a whole expression like this: int a = 12, b = 13; float c; c = (float)(a + b);