How i can know the size of all data type in my computer?
Use sizeof
to get the size of the type of variable (measured in bytes).
For example:
#include <stdint.h>
sizeof(int32_t)
will return 4
sizeof(char)
will return 1
int64_t a;
sizeof a;
will return 8
See http://publications.gbdirect.co.uk/c_book/chapter5/sizeof_and_malloc.html
You can apply sizeof
to each type whose size you need to know and then you can print the result.
sizeof(T)
will give you the size of any type passed to it. If you're trying to find out the size of all data types used or defined in a particular program, you won't be able to--C doesn't maintain that level of information when compiling.
The following program should do the trick for the primitive types:
#include <stdio.h>
int main()
{
printf("sizeof(char) = %d\n", sizeof(char));
printf("sizeof(short) = %d\n", sizeof(short));
printf("sizeof(int) = %d\n", sizeof(int));
printf("sizeof(long) = %d\n", sizeof(long));
printf("sizeof(long long) = %d\n", sizeof(long long));
printf("sizeof(float) = %d\n", sizeof(float));
printf("sizeof(double) = %d\n", sizeof(double));
printf("sizeof(long double) = %d\n", sizeof(long double));
}
This prints the number of "bytes" the type uses, with sizeof(char) == 1
by definition. Just what 1 means (that is how many bits that is) is implementation specific and likely depend on the underlying hardware. Some machines have 7 bit bytes for instance, some have 10 or 12 bit bytes.