The formal parameter test (int *&a) of a function in C language?

Source: Internet
Author: User

Today in a C code to see a function of the formal parameter is (int *&a) actually is this thing, which makes me very puzzled ah, do not know with so many address symbols what is the purpose? The address?

That's not necessary, just need to use a pointer to achieve such an effect, ah, exchange of data of two shaping variables, as long as the definition of a function swap (int* a,int *b) in the function to Exchange *a and *b values can be, so that the modification of the parameters and change the role of the arguments ah.

So I went to the library to get a C language grammar books, found that the & symbol is the role of the address, then *& is a what thing, has not seen.

Finally in a C + + book also see & this symbol, actually looked at another usage,"reference" operator. is placed after the type, such as int &a so that & is not the meaning of the address, but also to the formal parameter a reference.

Give me an example, please.

The reference parameter swap (Int&a,int &b) is then called when only swap (A, a, b) can also be used to achieve the role of the address, in fact, the reference parameter to the argument for an alias only, the operation of reference parameters is actually the operation of the arguments.

This usage is not seen in C, has occurred in C + +, through the & operator in C + + to do the use of reference, then to explain the function parameter test seen today (int* &a);

As I've said before,,& is used as a reference, and is placed after the type, which is int* as an shaping pointer type, then int* &a This parameter a represents the int* type reference argument

When using the call, int * a=&b; Test (a); The effect is that manipulating a pointer in the test function is equivalent to the A pointer in the action argument.

Alas, the friend who knows the pointer sees this kind of usage, this many superfluous. It's so complicated.

Said so much, said oneself are foggy, if have a friend to read this article still have not clear, welcome to ask questions, mutual progress.

The formal parameter test (int *&a) of a function in C language?

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.