CpSc 146 : Introduction to Programming
Expressions

Modifying the value of a variable:

  1. Input statement
    • cin >> length;
    • cin >> length >> width;
    • Semantics
      • wait for the user to enter a value
      • place the value into the memory location associated with the value
    • Potential error : not enough room allocated for variable (user may enter incorrect type)
  2. Assignment statement
    • General format: Variable = Expression
    • perimeter = length + length + width + width;
    • Semantics
      • evaluate the right hand side (rhs)
      • use operator precedence
      • use type rules for operators
      • possibly typecast result to the lhs type
      • place result in memory for variable
    • Potential error
      • Incorrect types for operators
      • Division by 0
      • Typecasting results in loss of precision
      • Not enough room in memory (type mismatch)

Now, let's examine some of the details that make a difference!
The types of variables is important
Mathematical operations are affected by the order of operations, the particular symbol, and the type of variables

More Assignment Statements


More Programming Basics


Formatting Output


Characters and Strings AGAIN


Library functions