Variables and Data Types

Variables, the int, long long, double, char and bool types, arithmetic and integer division.

Programs work with data: numbers, characters, text. To store data you need variables — named "memory cells". In C++ every variable has a type that determines what it can hold. The main types you will need: • int — integers up to about 2 billion (2·10⁹); • long long — big integers up to 9·10¹⁸, the competitive programmer's workhorse; • double — floating-point numbers, e.g. 3.14; • char — a single character in single quotes, e.g. 'A'; • bool — a logical value: true or false.
C++

Declaring variables of different types

Note: bool prints as 1 (true) or 0 (false). Numbers support the usual operations: addition +, subtraction -, multiplication *, division / and remainder %. An important C++ quirk: dividing two integers discards the fractional part. 7 / 2 equals 3, not 3.5. The remainder: 7 % 2 equals 1. The remainder is an extremely common trick in problems: for example, a number is even when n % 2 == 0. A classic beginner mistake is overflow: multiply two ints worth a billion each and the result no longer fits in an int — you get garbage. For large values always use long long.
C++

Arithmetic, integer division and long long

Task: create two variables with the values 15 and 4. Print their sum, difference, product, integer quotient and remainder — each on its own line. Then mark the lesson as completed and move on to reading input.
Доска