A.4. Chapter 4: OperatorsA.4.1. Quiz
The fourth expression evaluates to 5, not to true . Thus, if you write: z = x = y; and y has the value 5, then the order of operations is that the value in y (5) is assigned to x , and the value of the expression x=y , which is 5, is assigned to z .
A.4.2. Exercises
namespace operators { class exercise { static void Main( ) { int x = 25; int y = 5; System.Console.WriteLine("sum: {0}, difference: {1}, product: {2}, quotient: {3}, modulus: {4}.", x + y, x - y, x * y, x / y, x % y); } } } The output looks like this: sum: 30, difference: 20, product: 125, quotient: 5, modulus: 0.
static void Main( ) { int varA = 5; int varB = ++varA; int varC = varB++; Console.WriteLine( "A: {0}, B: {1}, C: {2}", varA, varB, varC ); } The output looks like this: A: 6, B: 7, C: 6
namespace operators { class exercise { static void Main( ) { int myInt = 5; int myOtherInt = myInt; System.Console.WriteLine("initial values: myInt: {0}, myOtherInt: {1}\n", myInt, myOtherInt); // prefix evaluation myOtherInt = ++myInt; System.Console.WriteLine("prefix evaluation myInt: {0}, myOtherInt: {1}\n", myInt, myOtherInt); // postfix evaluation myInt = 5; myOtherInt = 5; myOtherInt = myInt++; System.Console.WriteLine("postfix evaluation myInt: {0}, myOtherInt: {1}\n", myInt, myOtherInt); } } } The output looks like this: initial values: myInt: 5, myOtherInt: 5 prefix evaluation myInt: 6, myOtherInt: 6 postfix evaluation myInt: 6, myOtherInt: 5 |