Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integer literal with single quotes? [duplicate]

What exactly as been assigned to value? I am surprised that this has compiled at all.

//g++  7.4.0

#include <iostream>

int main()
{
    auto value = 123'456'7;
    std::cout << value << std::endl;

    value += 1;
    std::cout << value << std::endl;
}

outputs:

1234567
1234568

1 Answers

Since C++14,

from https://en.cppreference.com/w/cpp/language/integer_literal

Optional single quotes(') may be inserted between the digits as a separator. They are ignored by the compiler.

like image 178
Jarod42 Avatar answered Oct 22 '25 03:10

Jarod42



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!