In C and C ++, pointers are a very important part,ProgramYou can use pointers to find the data to be operated and executable functions.Code. Many people will understand the differences between pointers and addresses, but few can tell the difference clearly.
Pointers can be divided into two types: function pointers and data pointers. The biggest difference between a pointer and an address is that a pointer has a type and an address has no type. Of course, we can find functions and data through absolute addresses, but the addresses are of no type and cannot perform arithmetic operations on the addresses, when operations such as arrays are involved, the address auto-increment and auto-increment cannot be used to access various variables of the array. However, by referencing the pointer, you can easily access each element of the array by performing a series of addition, subtraction, and subtraction operations on the pointer.
Therefore, pointers are composed of addresses and types. pointers to data not only record the address where the data is stored in the memory, but also record the data type, that is, the memory occupies several bytes, which is not available to the address. The pointer to the function not only records the entry address of the function, but also records the type of the function, that is, the return value type of the function and the parameter type of the function.
There is also a special data type in C ++, that is, the object, which is a user-defined data type. It contains data and functions. But the object variables declared in the same class template each have a data member, but share a function Member, because for objects with a common class template, their data members may be different, but their function code for processing data is indeed the same, so they share a member function. At this time, the Object Pointer Points to the respective data members.
You must be very careful when using pointers. Never cross the border. Otherwise, unexpected results may occur. In addition, do not use Uninitialized pointers. This will access the memory at the location, which may cause a devastating disaster to the operating system, although robust operating systems generally do not allow this.