idk321's blog

By idk321, history, 4 years ago, In English

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?

  • Vote: I like it
  • 0
  • Vote: I do not like it

| Write comment?
»
4 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

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.