The simplest way to think about the difference between pointers and ordinary variables is to focus on the two different uses of integers:
Integers can represent serial numbers and quantities - the concept of quantity goes without saying. , but everyone understands the concept of serial numbers but not thoroughly.
2012 represents the year----this is the serial number, and the next year is 2013, that is, 2012+1 can get 2013, but what is the 1 here? Is it the year 1 AD? Is it the serial number or the quantity?
2012 is this year and 2013 is next year. Can the two be added together? What is serial number + serial number?
What are pointers? The pointer is a sequence number in the strict sense - the number of the storage location!
So pointer + quantity is a pointer ---- established
On the contrary, pointer - pointer is a quantity ---- established
Pointer + pointer ---- --Not true
There are two ways to access stored data at the source code level in C and C++: by name and by pointer - just like pressing by name (similar to variable name) or by pressing on the street The house number (similar to an address) is the same as when visiting a store.
1. A pointer variable is a type of variable. The value of a pointer variable is an address (also an integer). The value of an ordinary variable is an integer, a real number or other types. The main function of pointer variables is to modify local variables of other functions and access arrays. Pointer variables require additional space to store addresses. Since pointer variables indirectly access the pointed object, they are slightly slower than directly accessing the pointed object using ordinary variable names.
2. For example: int a=5; int *p = &a;
The pointer p is an integer pointer variable, which stores an address. This address belongs to a. address. You can use p to access a through the value operator *. Pointer variables are very flexible to use. A pointer variable only occupies four bytes, but it can access multiple data collections such as structures, linked lists, arrays, etc., and when accessing these variables, it directly accesses the memory, and the execution efficiency is high.