The C standard does not give a detailed specification of how many bytes the base type should be. Detailed with the machine, OS, compiler, for example, the same is in the 32bits operating system, VC + + compiler under the int type is 4 bytes, while Tuborc is 2 bytes.
Therefore, the width of the int,long int,short int may vary depending on the compiler. But there are several ironclad principles (Ansi/iso):
sizeof (short int) <=sizeof (int)
sizeof (int) <=sizeof (long int)
Short int should be at least 16 bits (2 bytes)
A long int should be at least 32 bits.
The following gives the number of bytes for the base data type under the different bits compiler:
16-bit compilers
Char:1 bytes
char* (i.e. pointer variable): 2 bytes
Short Int:2 bytes
Int:2 bytes
Unsigned int:2 bytes
Float:4 bytes
Double:8 bytes
Long:4 bytes
A long long:8 bytes
Unsigned long:4 bytes
< STRONG>32-bit compiler
char :1 bytes
char* (that is, pointer variables): 4 bytes (32-bit addressing space is 2^32, is a 32 bit, which is 4 bytes. Similarly 64-bit compiler)
short int : 2 bytes
int: 4 bytes
unsigned int : 4 bytes
Float: 4 bytes
double: 8 bytes
long: 4 bytes
long long: 8 bytes
Unsigned long: 4 bytes
64-bit compiler
Char:1 bytes
char* (i.e. pointer variable): 8 bytes
Short Int:2 bytes
Int:4 bytes
Unsigned int:4 bytes
Float:4 bytes
Double:8 bytes
Long:8 bytes
A long long:8 bytes
Unsigned long:8 bytes
The next page is a simple sample test (C + +):
Execution Environment, Windows 7 Ultimate + vc++6.0 + 32-bit system
#include <iostream>using namespace Std;void main () {cout<<sizeof (char) <<endl; 1 cout<<sizeof (short) <<endl; 2 cout<<sizeof (int) <<endl; 4 cout<<sizeof (long) <<endl; 4 cout<<sizeof (float) <<endl; 4 cout<<sizeof (double) <<endl; 8 cout<<sizeof (char *) <<endl; 4 cout<<sizeof (short *) <<endl; 4 cout<<sizeof (int *) <<endl; 4 cout<<sizeof (long *) <<endl; 4 cout<<sizeof (float *) <<endl; 4 cout<<sizeof (double *) <<endl; 4//cout<<sizeof (void) <<endl; This sentence cannot be compiled, possibly because void represents empty, not including whatever thing cout<<sizeof (void *) <<endl; 4 (relative to the previous sentence, this sentence is very well understood.) "Void *" is a pointer)}
C, C + + data type accounted for the number of bytes