Representing big numbers in source code for readability?

后端 未结 5 2111
难免孤独
难免孤独 2020-11-27 23:23

Is there a more human-readable way for representing big numbers in the source code of an application written in C++ or C?

let\'s for example take the number 2,

5条回答
  •  北荒
    北荒 (楼主)
    2020-11-28 00:04

    For C++1y you can now use single quote(') as a digit separator. Based on N3781: Single-Quotation-Mark as a Digit Separator which has finally been accepted. Both gcc and clang have supported this feature as part of their C++1y implementation.

    So the following program (see it live for clang):

    #include 
    
    int main(){
        std::cout << 2'345'879'444'641 << std::endl ;
    }
    

    will output:

    2345879444641

提交回复
热议问题