Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - What are the advantages of using pointers in C++?
What are the advantages of using pointers in C++?
Pointer is more flexible to use. If it is beneficial, according to my usual programming experience, there are probably several points:

1. In data transmission, if the data block is large (such as data buffer or large structure), then the pointer can be used to transmit the address instead of the actual data, which improves the transmission speed and saves a lot of memory.

2. Data conversion, using flexible pointer type conversion, can be used for data type conversion, and is often used to fill communication buffers. For example, if the type of data buffer is char buf, buf[4~7] is a value and the type is int, you can use the following statement to assign values:

* (short *) & buf[0]= cm did;

* (short *) & buf[2]= type;

*(int *)& amp; Buf[4]= value;

3. String pointers are the most convenient and commonly used.

4. The function pointer is in the form of #define PMYFUN (void*)(int, int), which can be used in a large number of examples of branch processing. For example, a communication executes different types of commands according to different command numbers, and an array of function pointers can be established for divergence.

5. In data structure, many applications such as linked list, tree and graph are inseparable from pointers.