convert from long long to int and the other way back in c++

前端 未结 3 1607
故里飘歌
故里飘歌 2021-02-01 06:33

How to convert from long long to int and the other way back in c++ ?? also what are the properties of long long , especially its maximum size, thank in advance ..

3条回答
  •  独厮守ぢ
    2021-02-01 06:45

    Type long long is typically 64 bits.

    Type int is likely to be 32 bits, but not on all machines.

    If you cast an int to a long long, you can do

    my_long_long = (long long) my_int
    

    and it will be just fine. If you go the other direction, like

    my_int = (int) my_long_long
    

    and the int is smaller than 64-bits, it won't be able to hold all the information, so the result may not be correct.

提交回复
热议问题