Блог пользователя idk321

Автор idk321, история, 4 года назад, По-английски

In Java int was a number with a maximum of 2^32 while in C++ the guaranteed maximum of int is not necessarily more than 2^16. Should I therefore always use long when I used int in Java? But, if I look at the code of other competitors, they mostly use int?

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
4 года назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

Yes you are right, it's not guaranteed to be 32 bits, however, in online platforms of competitive programming and almost on every machine nowadays, it is proven (by experience), that ints are 32 bits and long longs are 64 bits. There is a correlation between size of integers and machines architecture and/or operating system which is not something to change often. Therefore don't worry, you may rely on the fact that ints are at least 32 bits wide. If you want to make sure, you can run cout << 8 * sizeof(int); in custom test.