Summary Basis of algorithms and data structures, pointers and memory

Data structure is defined

  How do we put a lot of real and complex problems in order to save specific data types and specific storage structure into the main memory (RAM), and on this basis to achieve a certain function (such as finding an element, remove an element , the appropriate action to sort all elements performed, this operation is also called algorithms)

  + Data Structures = relation individual subject

  Arithmetic operation on the stored data =

  Measure algorithm:

  •     Time Complexity: Probably the number of program to be executed, rather than execution time
  •     Space complexity: during the execution of the algorithm is probably occupied by the maximum memory
  •     Degree of difficulty
  •     Robustness

 

The basic concept of memory:

  1. The memory devices are used to store data. Speed ​​between its storage registers and a hard disk.

  2. CPU memory is the only large-capacity storage device that can be accessed only by the CPU to perform after all the hard drives in the program and data must be loaded into memory. Note: CPU can not directly process the data on your hard disk!

  3. Memory problems are one of the core problems in software development! Such as: memory allocation, release, when memory allocation, when was it released? Who allocation and release? Assigned in what place? How to access?

  4. The memory storage space is a linear one-dimensional multi-bytes.

  And 5. The basic unit of memory is divided into bytes.

  6. Each byte contains 8 bits, each bit storing a 0 or a 1.

  7. byte number and correspondence. Each byte has a uniquely determined number, a number corresponding to one byte, this number is also called bytes.

  8. The size of a system that can manage memory space depends on the number of binary digits to participate. Such as: DOS system 20-bit addressing scheme, i.e., 2 ^ 20B may be controlled 1MB memory.

Software running relationship with the memory (garbage)

  Memory is used under the unified management of the operating system!

  1. Before running the software required to run the operating system application storage space, enough free space in the memory, the operating system will allocate some memory and external memory copy of the software stored in the memory space, and start the software !

  2. During the operation of the software, the software is no longer occupied by the memory space allocated to other software

  3. When the software has finished running, the operating system will recover the memory space (Note: the operating system does not clear the memory of the legacy data space) in order to be assigned to another software. Summing up the appeal, a space is assigned to the software likely exist after the previous residual data used by other software, such data is called garbage data. So normally we as a variable, array, initialize the memory space to be allocated after a good storage space!

 

Define the pointer

  That address pointer, the address is the number of the memory cell, the range of non-negative integer from 0 to 2 ^ 8-1, can not be repeated, but the stored content can be repeated. Pointer variable is stored in the variable address memory cell, the memory cell content can not be stored.

. 1 #include <stdio.h>
 2  int main () {
 . 3      int * P; // P is the name of the variable, int * P indicates the variable value stored int type variables only, and can not store or other char types variables value 
. 4      int I = 10 ;
 . 5      int j;
 . 6      // p = & j; // Since no value j, the p unit does not receive an address uncertain, p will be filled as a spam number memory 
. 7      p = & I ;   // the address of the pointer variable i to p 
. 8      J = * p;   // Since the pointer variable p i of the received address, * p represents the variable i takes a value out of the address, and then assigned to J 
. 9      
10      the printf ( " % D = I, J =% D, D * P =% " , I, J, P *);   // outputting ten 
. 11     return 0;
12 }

Hardware controlled by the operating system, compiler requesting the operating system to allocate memory for variables when the program runs out of memory will be recycled, but the data into a garbage data, has not been cleared.

 

How common is to modify the value of the variable in the calling function called function?

  1. The argument is the address of the relevant variables

  2. The type of the parameter as to the type of variable is a pointer variable

  3. In the called function by a parameter variable name * mode, can modify the value of a variable main function

. 1 #include <stdio.h>
 2  void F ( int * P) {
 . 3      * P = 100 ;
 . 4  }
 . 5  int main () {
 . 6      int I = . 9 ;
 . 7      F (& I);
 . 8      the printf ( " % D " , I); // output 100, instead. 9 
. 9      return  0 ;
 10 }

 

Guess you like

Origin www.cnblogs.com/sunbr/p/11247305.html