Skip to content

Operators and Types

Chapter 2

Overview

This 27-minute video is an overview of the second part of Chapter 2.

Casting numbers between ints and doubles

TIP

This video describes opening Atom. Instead of what is shown, open your code in VS Code by typing code casting.cpp.

Arithmetic Operators in C++

The C++ arithmetic operators.
OperatorName
+addition
-subtraction
*multiplication
/division
%modulus (or remainder) operator
++increment
--decrement

The following video explains the increment, decrement, and modulus operators.

  • Increment operator: increase variable by 1
    • Pre-increment: ++variable
    • Post-increment: variable++
  • Decrement operator: decrease variable by 1
    • Pre-decrement: --variable
    • Post-decrement: variable--

What is the difference between the following?

After watching the video, check your understanding by determining what alpha and beta equal in each of these examples.
Pre-incrementPost-increment
int alpha = 5;int alpha = 5;
int beta = ++alpha;int beta = alpha++;