Skip to content

Trivia impact: real

The Apostrophes That Are Part of a Number

grouped digits, with no string and no comment

std::cout << 1'234'567 << "\n";
std::cout << 0b1010'0101 << "\n";

Does this compile? What does it print?

Answer
1234567
165

Both apostrophe-filled spellings are integer literals, and neither apostrophe changes the number's value.

Why

[lex.icon] permits separating single quotes inside the digit sequence of an integer literal and says they are ignored when determining its value. The first literal is decimal 1234567; the second is binary 10100101, or decimal 165. The apostrophe is not a character literal, a quote, or an operator here — it is lexical punctuation between digits.

Where it shows up

This is a practical way to make large decimal counts and bit masks reviewable without changing their type or value. Conventional three-digit decimal and four-digit binary or hexadecimal groups make the punctuation earn its keep, so the feature has real everyday readability value.

Takeaway: a single quote between digits is ignored inside a C++ integer literal.

Try it: g++ -std=c++17 main.cpp -o demo && ./demo

Open in Compiler Explorer ↗ Quiz this entry