<< Chapter < Page | Chapter >> Page > |
Single values by themselves are important; however we need a method of manipulating values (processing data). Scientists wanted an accurate machine for manipulating values. They wanted a machine to process numbers or calculate answers (that is compute the answer). Prior to 1950, dictionaries listed the definition of computers as " humans that do computations". Thus, all of the terminology for describing data manipulation is math oriented. Additionally, the two fundamental data type families (the integer family and floating-point family) consist entirely of number values.
Let's look at an example: 2 + 3 * 4 + 5 is our expression but what does it equal?
Parentheses would change the outcome. (2 + 3) * (4 + 5) evaluates to 45.
Parentheses would change the outcome. (2 + 3) * 4 + 5 evaluates to 25.
Each computer language has some rules that define precedence and associativity. They often follow rules we may have already learned. Multiplication and division come before addition and subtraction is a rule we learned in grade school. This rule still works. The precedence rules vary from one programming language to another. You should refer to the reference sheet that summarizes the rules for the language that you are using. It is often called a Precedence of Operators Chart. You should review this chart as needed when evaluating expressions.
A valid expression consists of operand(s) and operator(s) that are put together properly. Why the (s)? Some operators are:
Most operators are binary, that is they require two operands. Within C++ there is only one trinary operator, the conditional. All of the unary operators are on the left side of the operand, except postfix increment and postfix decrement. Some precedence charts indicate of which operators are unary and trinary and thus all others are binary.
Notification Switch
Would you like to follow the 'Programming fundamentals - a modular structured approach using c++' conversation and receive update notifications?