What are the largest signed and unsigned ints in c++?
What are the largest signed and unsigned ints in c++?
The "sizes" of the integral types is implementation defined. To find the limits any of the integral types can hold for a given implementation you can use some of the members of the numeric_limits class.
Jim
The specific sizes are implementation defined, but the standard does clearly state the minimum range for all of them. For int/unsigned int, the ranges are -32767 to 32767, and 0 to 65535, respectively. Int and unsigned int may have wider ranges than this, but this is the minimum that the standard requires. it's actually very common for the ranges to be -2,147,483,647 to 2,147,483,647 and 0 to 4,294,967,295 respectively.
Source: Fundamental types - cppreference.com
What can this strange device be?
When I touch it, it gives forth a sound
It's got wires that vibrate and give music
What can this thing be that I found?
Hello,
Found this a long time ago, a quick runtime check.
This works with gcc, don't know about the MS compiler.
Code:unsigned int max = -1; printf("max = %u\n", max);//max = 4294967295
Regards
I would never rely on code like that lol.
If you want to set all the bits of a region of memory, use memset.
What can this strange device be?
When I touch it, it gives forth a sound
It's got wires that vibrate and give music
What can this thing be that I found?
Ah, it is indeed well-defined behavior. It's just not very self-documenting or clear code.
It looks like they were using that behavior to set all the bits of an unsigned int to see its largest value which is why I suggested using memset instead. These kinds of things may work but they seem hackish to me in the sense that they don't convey intent and require a tab with the C++ standard open.