Operators and Types
Chapter 2
Overview
This 27-minute video is an overview of the second part of Chapter 2.
Casting numbers between int
s and double
s
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++
Operator | Name |
---|---|
+ | 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++
- Pre-increment:
- Decrement operator: decrease variable by 1
- Pre-decrement:
--variable
- Post-decrement:
variable--
- Pre-decrement:
What is the difference between the following?
Pre-increment | Post-increment |
---|---|
int alpha = 5; | int alpha = 5; |
int beta = ++alpha; | int beta = alpha++ ; |