For example, in C language, why should I specify a type for declaring a pointer?
When I learned 8086 assembly, I found a phenomenon:
For DB-type arrays, Si (source address change register) can obtain the address of the next element in the array once as long as Inc;
For DW-type arrays, Si needs Inc twice to obtain the address of the next element in the array;
I think:
Si can be used as a pointer. Each time Si ++ points to the space address of the next byte.
For an array whose space is not 1 byte, perform Si ++ several times until the number of bytes moved by the pointer is the space occupied by each element in the array.
The minimum unit of memory space is byte, and the minimum distance between pointer movement is 1 byte.
In the C language, the pointer ++ operation does not need to calculate the number of times the pointer needs to be ++, And the compiler automatically calculates the number of times, you can obtain the address of the next element in the array as long as ++ is used, regardless of the type;
Of course, the premise is that the type is specified when the pointer is declared, for example:
Char * PC, STR [] = "12345"; double * PD, num [] = {1, 2, 4, 5}; Pc = STR; Pd = num;
PC ++, which points to the address of the memory space of the next byte.
PD ++, which points to the address of the memory space of the next 8 bytes.
Conclusion:
When a pointer is declared, the pointer type determines the unit distance of the pointer movement, that is, the address of the memory space to move.