Erin's CS stuff

Home Getting Started Topic Explanations Coding Quick Quides

Expressions Quick Guide

For more information on the order of expression evaluation, see Operator Precedence and Associativity

Type Application Example Notes
arithmetic doing math with values
  • + - * / %
  • an expression with two int values evaluates to an int
    • beware of integer division!
  • an expression with int and double values evaluates to a double
  • since chars are stored as numerical values, you can do math (and comparisons) with them, too!
relational comparing values
  • < > <= >= == !=
  • these always evaluate to either 1 or 0 (true or false)
  • to determine if a values is within a range, relational expressions must be combined with logical expressions
logical combining multiple truths
  • && ||
  • Logical expressions can short circuit or skip evaluation if the first expression determines the result. For example,
    • if the first part of a && expression is 0 (false), the second part won't evaluate because it won't change the overall (false) result
    • if the first part of a || expression is 1 (true), the second part won't evaluate because it won't change the overall (true) result