C Programming (1) - Data type

In order to facilitate brush algorithm, C language review it again

https://www.bilibili.com/video/BV1At411g7ou  zero-based courses

 

Basic data type (can not be divided):

  Integer:

  Short integer (short)

  Integer (int)

  Longs (long)

  Unsigned int (unsigned int)

 

  Float:

  Single precision (float)

  Double precision (double)

  Extended precision (long double)

 

  Character (char)

 

  Null type (void)

 

Configuration data types (a combination of a plurality of types together):

  Array

  Structure (struct)

  Public bodies (union)

  pointer

 

For the number of bytes occupied by the basic data types, C standard does not give a specific predetermined number of bytes which correspond to the basic types, but with the machine, the OS, compiler related, such as: 32bits same operating system, the compiler of VC ++ int type lower 4 bytes, while the lower tuborC is 2 bytes.

Therefore int, long int, short int width may vary with the compiler, but definitely a few principles (ANSI / ISO formulation): 

  • sizeof(short int)<=sizeof(int)

  • sizeof(int)<=sizeof(long int)

  • short int should be at least 16 bits (2 bytes)

  • long int should be at least 32

 

The number of bytes occupied by the basic data types in different compilers bits:

16-bit compiler:

short int: 2 bytes

int: 2 bytes

long: 4 bytes

long long: 8 bytes

unsigned int: 2 bytes

unsigned long: 4 bytes

float: 4 bytes

double: 8 bytes

char: 1 byte

char * (i.e. pointer variable): 2 bytes 


Compiler 32:

short int: 2 bytes

int: 4 bytes

long: 4 bytes

long long: 8 bytes

unsigned int: 4 bytes

unsigned long: 4 bytes

float: 4 bytes

double: 8 bytes

char: 1 byte

char * (i.e. pointer variable): 4 bytes (32-bit address space is 2 ^ 32, i.e., 32 'bit, which is 4 bytes; Similarly compiler 64)


64-bit compiler:

short int: 2 bytes

int: 4 bytes

long: 8 bytes

long long: 8 bytes

unsigned int: 4 bytes

unsigned long: 8 bytes

float: 4 bytes

double: 8 bytes

char: 1 byte

char * (i.e. pointer variable): 8 bytes

 

Machine word: refers to a computer-digit integer arithmetic can be processed by binary data (i.e., fixed-point integer arithmetic integer arithmetic). Machine word for word length is fixed-point arithmetic operations, usually the internal data path width of the CPU, now generally 32-bit (4-byte), 64 bit (8 bytes), there are 16 (2 bytes).

On most computers:

  short int represents two bytes long, short only modifies int, short int can be omitted to Short;

  long int and modifications can double, modified to long int (can be omitted as long), generally it represents four bytes, when the modified long double, generally designated 10 bytes;

  unsigned and signed int char and modifications can, under normal circumstances, and the default char is signed int, float and double real numbers are always signed, unsigned modification can not be used;

  bool type (Boolean, also known as Logical) data values ​​can only be false (false) or true (true), the number of bytes occupied bool type data may be different in different compilation system, VC + +6.0 compiler environment accounted for a byte data type bool.

  With sizeof (data type) byte length of a data type may be determined, for example, with the following statement:
    COUT << "int size of IS" << sizeof (int) << endl;
    16-bit computer will output:
    size Of int is 2

Guess you like

Origin www.cnblogs.com/zimsky/p/12611663.html