C-language pointer variable as function parameter

Source: Internet
Author: User

0x01

A pointer variable acts as a function parameter by transferring the address of one variable to another function.

0x02

Simple example: Although the function can be realized, but the meaning is different.

The correct wording:

 

1#include <stdio.h>2 3 voidShuchu (int*p)4 {5printf"%d\n", *p);6 }7 8 intMain ()9 {Ten     intA; One     int*PA; Ascanf"%d", &a); -PA = &A; -Shuchu (PA);//PA is Address the}

A deceptive notation:

  

1#include <stdio.h>2 3 voidShuchu (int*p)4 {5printf"%d\n", *p);6 }7 8 intMain ()9 {Ten     intA; One     int*PA; Ascanf"%d", &a); -PA = &A; -     //Shuchu (*PA); the}

Note the 14th line, is a deceptive way of writing, although the use of pointers, but the same as useless, because only the assignment, and then still use the original value;

In general, it is important to emphasize that pointers are used as function parameters to pass the address of a variable to a parameter instead of passing the original value.

C language pointer variable as function parameter

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.