Unformatted text preview: agazine http://www.tmcnet.com/usubmit/2007/08/24/2886494.htm C++ Expressions C++ Expressions Expressions consist of operators, literals and identifiers. Literals are direct representations of data such as 2.4, 5 or 1.0e5 (which is the way a computer writes 1.0×105). Identifiers are names given to data objects in declarations. In the previous program x and y were identifiers. Operators transform data. These include +(add), * (multiply), =(assign), plus many others. Operators Operators Operators are the most interesting of the three since they transform data.
Lite r als operator
s ifier t den I new data Operators that operate on one operand (data object) are unary, those that operate on two operands are called binary. Mathematical Operators Mathematical Operators
Operator Meaning
sign change multiplication real division integer division remainder addition subtraction Arity
unary binary binary binary binary binary binary Placement
prefix infix infix infix infix infix infix Precedence
15 13 13 13 13 12 12 – * / / % +
– The Minus Operators – The Minus Operators – Two applications of “–” The difference is determined by whether the “–” is in front of a single literal or identifier or between two. int x, y, z; x = 5; y = – x; // here the “–” is a sign change z = x – 3; // here the “–” is a subtraction The Division Operators / The Division Operators / There are two “/” operators Integer division occurs if both operands are integers In this case the result is only the whole number part of the result. So the result is also an integer.
2/2 evaluates to 1; 5/2 evaluates to 2; 4/2 evaluates to 2 2/5 evaluates to 0 The Division Operators / The Division Operators / There are two “/” operators Real division occurs if any of the operands are not integers. Any of the operands that are not integers are converted to doubles before dividing
2/2 evaluates to 1; evaluates to 2 2.0/2.0 evalua...
View
Full Document
 Fall '07
 JeffRingenberg
 Scaffolding, OS, Computer program, Text editor

Click to edit the document details