C4

Cards (24)

  • Operators are used to perform operations on variables and values.
  • C++ divides the operators into the following groups:
    Arithmetic operators
    Assignment operators
    Comparison operators
    Logical operators
    Bitwise operators
  • Arithmetic Operators
    • are used to perform common mathematical operations.
  • +
    Addition
    Adds together two values
    x+y
  • -
    Subtraction
    Subtracts one value from
    another
    x-y
  • *
    Multiplication
    Multiplies two values
    x*y
  • /
    Division
    Divides one value by
    another
    x/y
  • %
    Modulus
    Returns the division remainder
    x % y
  • ++
    Increment Increases the value of a variable by 1
    ++x
  • -- Decrement
    Decreases the value of a variable by 1
    --x
  • Assignment Operators
    are used to assign values to variables.
  • Comparison operators are used to compare two values (or
    variables). This is important in programming, because it helps us to find answers and make decisions.
  • As with comparison operators, you can also test for true (1) or
    false (0) values with logical operators.
    Logical operators are used to determine the logic between
    variables or values
  • Use if to specify a block of code to be executed, if a specified
    condition is true.
  • Use else to specify a block of code to be executed, if the same
    condition is false
  • Use else if to specify a new condition to test, if the first
    condition is false
  • Use switch to specify many alternative blocks of code to be
    executed cout << x + y + z;
  • When C++ reaches a break keyword, it breaks out of the switch block.
  • The default keyword specifies some code to run if there is no case match:
  • Loops can execute a block of code as long as a specified condition is reached.
  • The while loop loops through a block of code as long as a specified condition is true
  • The do/while loop is a variant of the while loop. This loop will
    execute the code block once, before checking if the condition is true, then it will repeat the loop as long as the condition is true.
  • It is also possible to place a loop inside another loop. This is
    called a nested loop.
  • There is also a "for-each loop" (introduced in C++ version 11 (2011), which is used exclusively to loop through elements in an array (or other data sets)