Lecture+03

# Sotheresultisalsoaninteger 22evaluatesto1

This preview shows page 1. Sign up to view the full content.

This is the end of the preview. Sign up to access the rest of the document.

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.0e­5 (which is the way a computer writes 1.0×10­5). 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

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern