Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which type in c++ can store 2^63?

Tags:

c++

I need to store 2^63 natural number in my program. Int has 4 bytes: http://www.cplusplus.com/doc/tutorial/variables/ so it is 2^(8*4) = 2^32, which type should I use?

like image 243
Sławosz Avatar asked Jan 19 '23 11:01

Sławosz


1 Answers

You can use unsigned long long, but I would check that your compiler supports that type.

#include <iostream>
int main()
{
    std::cout<<sizeof(unsigned long long)<< " bytes" << std::endl;
    return 0;
}

Prints 8 bytes on my machine which is enough room to store 2^63.

like image 119
Jack Edmonds Avatar answered Jan 21 '23 00:01

Jack Edmonds