When passing pointer parameters, you must note that pointer Transmission

Source: Internet
Author: User

When passing pointer parameters, you must note that pointer Transmission

Passing pointer ParametersNote:
When the parameter pointer in the main function is passed to the parameter pointer of the called function, it means that the two pointers point to the same memory unit. In this case, when the called function uses the form parameter pointer to operate on the memory area, it is very likely that the two pointers (the form parameter pointer and the real parameter pointer) Point differently. This is not just caused by the malloc function (which denies the previous point of view ). If the parameter pointer still needs to be completed in the main function, it is wise to return the parameter pointer to the main function.
To stay away from this inconsistency, the best way is to always return.
PS:If you do not need to use the parameter pointer in the called function after the main function is called, you can safely use the parameter transfer between pointers and do not need to return it. In this case, you can also use the get address operator & to pass the address of the real parameter value to the shape parameter pointer of the called function.

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.