C language pointer and variable in Single Chip Microcomputer
Pointer and variable
Note: C Programming for Single-Chip Microcomputer in keil
If the pointer does not point to a variable declared in advance, confusion will occur.
Eg:
Scenario 1: Scenario 2:
Type * p, * q; Type * p, * q, pp, qq;
Assign a value to pointer p; p = & pp;
Assign a value to the pointer q; q = & qq;
The value of p or q may be normal, no problem (Type is a struct)
Conclusion: in scenario 2, it is the standard process of pointer usage. A variable is allocated first, and then the Pointer Points to the variable.
In scenario 1, no variables are defined. The pointer operation is used directly and an error occurs. I guess: Because the pointer is only used to store the address of the variable, no variable is defined now, the value assigned to the pointer may be stored randomly in the memory, and confusion may occur when the Pointer Points to them.
The pointer's own address and the address indicated by the pointer
Mcu c Programming in keil
Rf_packet_info * buff, buffer;
Uart_sendbyte (buff); uart_sendbyte (& buffer );
Buff = & buffer;
Uart_sendbyte (buff); uart_sendbyte (& buffer );
The result of the first serial port running after burning:
03 21 27
27 21 27
Output result after the first time:
27 21 27
27 21 27
Conclusion: The content stored in the uart_sendbyte (buff) pointer buff refers to the address of the variable, which is a random value before pointing to the variable;
Uart_sendbyte (& buff) pointer address;
The buffer address of the uart_sendbyte (& buffer) variable.