Well, the integral types in C and in most of the languages have something called limits , you can find a header in your C compiler called limits.h
where all the limits are in your platform current.
The subject with the limits, is the following:
A int
is 32 bytes, correct?
A long long
is 64 bytes.
Taking this to the hexadecimal system you can have the following values:
FF FF FF FF <- Int
FF FF FF FF FF FF FF FF <- Long long.
So, you have from 00 00 00 00 00 00 00 00
to FF 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 actual range of values available, since certain standards are used to represent the sign, for example the following program:
int main(void) {
int test = 0xFFFFFFF0;
printf("%d - %u\n", test, (unsigned int)test);
}
It will give you as a result:
-16 - 4294967280
And if you try to invert the bytes:
int main(void) {
int test = 0x0000000f;
printf("%d - %u\n", test, (unsigned int)test);
}
You will get the following result:
15 - 15
With all this, the size of some types (in bytes), this data may vary depending on the platform:
- char : 1 <- Este es de tipo integral.
- short : 2
- int : 4
- float : 4
- long : 8 (64 bits)
- long long : 8
- double : 8
Here below a program that shows it.
int main(void) {
printf("sizeof(char) == %d\n"
"sizeof(short) == %d\n"
"sizeof(int) == %d\n"
"sizeof(float) == %d\n"
"sizeof(long) == %d\n"
"sizeof(long long) == %d\n"
"sizeof(double) == %d\n",
sizeof(char), sizeof(short), sizeof(int),
sizeof(long), sizeof(float), sizeof(long long), sizeof(double)
);
}