C language pointer and variable in Single Chip Microcomputer

Source: Internet
Author: User

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.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.