In most of the videos they C
show a table with the type of data, its size and the range.
In the case of the INT
value is between -32768 a 32767
.
I would like to know what this affects, because place a value like this 33000
and it shows normal, which represents that 32767
and, failing that, the ranges in general
It happens that the rank of a
int
on some platforms is really that:-32768
a32767
(16-bit platforms). But on 32-bit platforms, theint
is bigger. You are probably on a modern platform (32 or 64 bit) so youint
can host a much larger range.With this code you can know the size of a
int
in your platform:Well, integral types in C and most languages have something called limits , you can find a header in your C compiler called
limits.h
where all the limits are on your current platform.The subject with the limits, is the following:
A
int
is 32 bytes, right? Along long
is 64 bytes.Taking this to the hexadecimal system you can have the following values:
So, you have from
00 00 00 00 00 00 00 00
toFF FF FF FF FF FF FF FF
in values for a long integer (long long).But! It happens that when it comes to making the subject of signs in integral types...
When a number has a sign, you only have half of its real range of values available, since certain standards are used to represent the sign, for example the following program:
It will give you as a result:
And if you try to invert the bytes:
You will get the following result:
With all this, the size of some types (in bytes), this data can vary depending on the platform:
Below is a program that demonstrates it.
As an additional reference, to know the current limits of a given type you can use the limits.h library (another C++ link ):