04opsAssign_3014

04opsAssign_3014 - Lecture File 04 January 7, 2008 COP 3014...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Lecture File 04 January 7, 2008 A. Ford Tyson 1 COP 3014 Lecture File 04 ± Operators and Assignment – expressions and statements 1 – arithmetic operators – data type conversions – operator precedence – functions and the math library Copyright 1997-present, Ann Ford Tyson ± Operator performs an action (+, - etc.) and generates a value ± Expression 2 – Comprised of operators, operands (variables, named constants, literal values) and function calls –Has a Value Data Type May have a side effect Statement ± A complete executable instruction, as defined by a programming language 3 ± C++ has a small, finite set of legal statements
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Lecture File 04 January 7, 2008 A. Ford Tyson 2 Assignment Expression Variable name Expression = 4 ± Value : value of right-hand side ± Type : data type of right-hand side ± Side effect : value of right-hand side is stored in variable's memory location data types must typically "match" Assignment Statement ± <assignment expr> ; ; is statement terminator ± int main ( ) 5 { int num; num = 4 * 5; ± Effect: 1. evaluate expression 4 * 5 2. store value "in" variable (its memory location) Arithmetic Operators Binary Operand Result Operators Type Type + * intege in if both 6 + - / integer int or real operands are int; real otherwise
Background image of page 2
January 7, 2008 A. Ford Tyson 3 Arithmetic Operators (continued) Binary Operand Result Operators Type Type % (modulus in in 7 % (modulus) int int Unary Operators: + and - e.g. -32 Integer Division ± / integer-only division (truncate result) ± % modulus (integer remainder) 8 ± E.g. How many hours and minutes are there in 375 minutes? 375 / 60 6 hours 375 % 60 15 minutes Integer Division p.2 ± E.g. Given that monthNum is an int variable in the range 1 to 12. Does it represent a month in which quarterly 9 interest is paid (Mar, Jun, Sep, Dec)? is
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 11

04opsAssign_3014 - Lecture File 04 January 7, 2008 COP 3014...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online