The memory and address of C language and some related basic concepts

Why does 32-bit operating system have 4G memory?

  • A 32-bit operating system is installed in a 32-bit computer. The CPU of a 32-bit computer is 32-bit, that is, the address bus is 32. The CPU processes the program and issues instructions to the address bus (the role of the address bus is to transfer addresses to the addressing space— —Find address) Because there are 32 address buses, you can pass the result of 2 to the 32th power. The addressing space will look for the corresponding number in the memory according to this result (the operating system will be Each byte is numbered, this label is the address), a number corresponds to a byte, so you can find 2 bytes of 32 bytes (ie 4G), so the computer can only find 4G memory, so A 32-bit system only "needs" to manage 4G memory, so a 32-bit operating system will only give 4G memory numbers when it is turned on, which means that a 32-bit operating system can only manage 4G memory.

What is memory

  • The place where the computer "temporarily" stores "data" (variables)—variables are stored in the memory when the program is executed. After the program is executed, the memory is released
  • Hard Disk: The place where the computer "permanently" stores "data" (files)
  • Memory is managed by the operating system

What is the heap

  • Freely allocated space, freely requested space is heap space

The nature of the address

  • If it is a 32-bit computer, then the address is a 32-bit binary number

The relationship between memory and address

  • One byte of memory will be assigned an address

Memory distribution (from small to large)

  • Code segment: storage code block (declaration of function)
  • Data segment: constants, global variables, static variables
  • Heap: freely allocated space
  • Stack: local variable storage place
    - a function and a distribution function in a different stack
    - then when a function to be executed, the system determines that the function will take up much space, so much space and then assign it as a stack
    - The address of the stack is allocated from the large address to the small address,
    -the allocation of data in a stack is allocated from the small address to the large address
    -the stack ----- first in, last out, first in, first out
  • System memory: the space occupied by system operation

Conversion relationship and unit

  • The smallest storage unit of memory is "bytes"
  • 1 byte = 8 binary bits
  • 1K = 1024 bytes; 1M = 1024K; 1G = 1024M
  • 1 hexadecimal digit = 4 binary digits

C language is a weakly typed language

  • How to distinguish: the data is stored in the memory and you can see that its data type is a strong type. Example: Most of the data type restrictions are static declarations, otherwise it is the
    opposite, and it is not seen as a weak type. Example: ASCLL A and 65 are both 65, so I can't tell if they are the same. JS is a strongly typed language.

The nature of variables

  • The variable name is just a code name, address.
  • The essence of variables is memory.
  • Where is the data written to the cpu
  • One byte 8 binary numbers 1
  • 8 bits per byte. 32 bit is 48=32, 64 bit is 88=64.
  • A pointer is a data type, specifically generated for an address.
  • Except for the code segment after the code is compiled, which function is currently called, how many lines the currently called function runs, and what variables are in this function, what are the values ​​of these variables, and where is the record? There is a stack.

The nature of pointers

  • All variables in C language have types
  • int type saves integer
  • Double-precision floating-point number saved by doublue type
  • The pointer saves the memory address

Memory ordering of array declaration

  • C language declares the length of the array to declare the array
  • Declared in the function in the stack memory, the result is also in the stack memory when the function is executed
  • If we are using pointers, if we use the memory space pointed to by a variable that we have not declared in the program, then we will get random values. C language does not do pointer safety check, as long as an address is given, an address is manipulated and the value is taken out

Guess you like

Origin blog.csdn.net/weixin_43806691/article/details/109373203