I have found varying answers to this question, and I know there must be one definitive answer. What is the minimum allocated memory size of the four main data types in C? int
, double
, float
, and char
are what I'm thinking of. Do the signed
or unsigned
types alter the size in any way?
You can use sizeof(variable)
:
As an example running this on my local machine:
sizeof (char) = 1
sizeof (double) = 8
sizeof (float) = 4
sizeof (int) = 4
sizeof (long) = 4
sizeof (long long) = 8
sizeof (short) = 2
sizeof (void *) = 4
Note: the values you get may be determined by OS/Compiler/CPU architecture.