// Dave Goldsmith // Redwood High School // C++ Computer Programming // October 3, 1999 // Precedence.cpp /* This program demonstrates how precedence of operators can affect the results of calculations. (Refer to a textbook for charts showing the specific rules of precedence for all of the C++ operators.) By using parentheses, the same expression can be made to produce a variety of answers. */ #include // Required for 'cin' and 'cout' int main() { int x, y; x = 8; y = 3; cout << 3 + --x % 4 * --x - ++y * 2; cout << endl << endl; x = 8; y = 3; cout << (3 + --x) % 4 * (--x - ++y) * 2; cout << endl << endl; x = 8; y = 3; cout << 3 + --x % ((4 * --x) - ++y) * 2; cout << endl << endl; x = 8; y = 3; cout << 3 + --x % (4 * --x) - ++y * 2; cout << endl << endl; return 0; }