[C language] data types, storage classes

ref


type of data

Integer type

type size scope
char 1byte -128~127
unsigned char 1byte 0~255
int 2/4byte -32768~32767 / − 2 31 -2^{31}231 ~2 31 − 1 2^{31}-12311
unsigned int 2/4byte 0~65535 / 0 00 ~2 32 − 1 2^{32}-12321
short 2byte -32768~32767
unsigned short 2byte 0~65535
long 4/8byte − 2 31 -2^{31}231 ~2 31 − 1 2^{31}-12311 /− 2 63 -2^{63}263 ~2 63 − 1 2^{63}-12631
unsigned long 4/8byte 0 00 ~2 32 − 1 2^{32}-12321 /0 00 ~2 64 − 1 2^{64}-12641
long long 8byte − 2 63 -2^{63}263 ~2 63 − 1 2^{63}-12631
  • 16-bit operating system: int occupies 2 bytes, long occupies 4 bytes
  • 32-bit operating system: int occupies 4 bytes, long occupies 4 bytes
  • 64-bit operating system: int occupies 4 bytes, long occupies 8 bytes

floating point type

type size scope precision
float 4byte 1.2E-38~3.4E+38 6 significant bits
double 8byte 2.3E-308~1.7E+308 15 significant bits
long double 16byte 3.4E-4932~1.1E+4932 19 significant bits

Embedded common replacement

typedef char int8;
typedef volatile char vint8;
typedef unsigned char uint8;
typedef volatile unsigned char vuint8;
typedef int int16;
typedef unsigned short uint16;
typedef long int32;
typedef unsigned long uint32;

storage class

  • auto: default storage class, can only be used in functions, can only modify local variables
    int year;
    auto int month;   // 两个相同存储类得变量
    
  • register: local variables stored in registers instead of RAM, maximum size = register size, cannot use &operators (no memory location)
    register int day;
    
    • Only used for variables (counters) that need fast access; may be in registers (depending on hardware)
  • static: keep the existence of local variables during the life cycle of the program, if in the file, the scope is limited to the file
    static int hour;
    
  • extern: provide a reference, the variable name points to a previously defined storage location
    extern int minute;
    

operator

  • ^: or, dissimilar=1
  • &: return variable address
  • *: points to a variable
  • ?:: conditional expression
    (a==10)?20:30
    

priority


function

  • Call by value: The actual value is assigned to the formal parameter of the function, and the modification of the formal parameter does not affect the actual parameter
  • Call by reference: pass a pointer to a formal parameter, the operation is equivalent to the operation of the actual parameter itself

scope

  • The global variable has the same name as the local variable, and the local variable is used first in the function
    • Formal parameters are also treated as local variables of the function

Guess you like

Origin blog.csdn.net/weixin_46143152/article/details/126653280