xampla - 5 months ago 49

C++ Question

So I think I'm a bit confused. I'm searching information about the limits of the differents types of integers. I've seen that the limit for unsigned long int is 4294967295 but when I do:

`cout << numeric_limits<unsigned long int>::max() << endl;`

I'm getting:

`18446744073709551615`

And if I'm not wrong this number is the limit of unsigned long long, isn'it? So what is happening?

Thank you

Answer

I've seen that the limit for unsigned long int is 4294967295

Whoever told you that was *wrong*.

The limit for `unsigned long int`

will usually be that on systems for which the type is 32-bit.

But yours is evidently 64-bit, so you have a different limit.

this number is the limit of unsigned long long, isn'it?

Again, you're making assumptions about type width.

The width of types varies across compilers/platforms.

If you want to use types with a fixed size, then those do exist.