← C++ from Scratch
Lesson 8 of 62 · 10 XP
Data types
Theory and problem statement
Machine translation, not yet reviewed by a native speaker.
| type | what it holds | example |
|---|---|---|
int |
an integer (usually 32 bits, ±2·10⁹) | 42 |
long long |
a 64-bit integer (±9·10¹⁸) | 10000000000LL |
unsigned |
an unsigned integer | 4000000000u |
double |
a double-precision fractional number (~15 digits) | 3.14 |
float |
a single-precision one (~7 digits) | 3.14f |
char |
a character (1 byte) | 'A' |
bool |
true / false |
true |
std::string |
a string | "Hello" |
Important effects:
- integer division:
7 / 2 == 3— the fractional part is dropped. If you need 3.5, make one operand fractional:7 / 2.0; - overflow: an
intdoesn't stretch —2000000000 + 2000000000goes past the limit. For big sums uselong long; - casting:
static_cast<double>(a) / b— explicitly makeafractional; - a
charis a number:'A' + 1 == 66, andstatic_cast<char>('A' + 1) == 'B'.
Task. Read two integers a and b. Print on three lines: the integer quotient, the remainder (%)
and the exact (fractional) quotient with 2 decimal places.
Sign up for free to solve this task right in your browser: code editor, running, test checks and hints.