In C ++ data types, operators and expressions

C language data types can be divided into four types: basic data types, data structure type, data type and null pointer type.

1, the basic data types

     It can be divided into three basic data types: integer, character, floating point

Plastic: short integer, basic integer, long integer, long integer.

    The number of bytes generally occupy the same data type in different compilers are also different. Statistics about the introduction in CodeBlock compiler.

          Type the name of the number of bytes

          short[int]    2

          int         4

          long[int]     4

          long long[int]       8

   It provided a method can calculate the number of bytes sizeof () in C ++, the following examples:

    

 // the sizeof (I) the number of bytes required operator 
    short SH = 2 ; 
    the printf ( " number of bytes of short: D% \ n- " , the sizeof (SH));
     int I = . 1 ; 
    the printf ( " int word number of knots:% D \ n- " , the sizeof (I));
     long L = . 1 ; 
    the printf ( " number of bytes long:% D \ n- " , the sizeof (L));
     long  long LL = 24 ; 
    the printf ( " bytes long long as: D% \ n- ' , the sizeof(LL));
     float FL = 2.1111 ; 
    the printf ( " number of bytes float is:% d \ n- " , the sizeof (FL));
     double Dou = 2.333 ; 
    the printf ( " number of bytes is double:% d \ n- " , the sizeof (Dou));
     Long  Double LD = 2.333 ; 
    the printf ( " number of bytes long double:% D \ n- " , the sizeof (LD));
     char CH = " a " ; 
    the printf ( " char of number of bytes:% D \ n- " ,sizeof(ch));

Calculation results are as follows:

 Also integer data stored in the memory mode is stored in binary form. In fact complement value in the form of representation. Complement positive number and original codes coincide, if the number is negative, its complement is calculated as: the absolute value of the binary number, you get a negation plus complement.

such as:

short s = 10;

Variable s stored in the memory by:

0000 0000 0000 1010

and

short s = -10;

Variable s stored in the memory by:

1111 1111 1111 0110

As can be seen from the above first bit is 0 for positive, 1 for negative.

Character

In the C language character occupies only one byte in memory and corresponding ASCII codes are stored, and thus stored in the form of an integer is the same.

 

Guess you like

Origin www.cnblogs.com/LimorC/p/11210570.html