Pointer array vs array pointer pointer function vs function pointer

Source: Internet
Author: User

In distinguishing these important concepts, let's first review the three values of C in the previous one, because the three values of the address is the same, so there are often rumors that they are the first element of the address. This argument is not correct. Why is it wrong to say it?

First, define a pointer, assign three values to it

*p=ar;

*p=&ar[0];

*p=&ar//Error

An error occurred in the expression *p=&ar after the program was compiled , stating that ar is not a pointer type. ar is the array name that represents the entire space, so ar should be an array pointer.

These four concepts seem easy to confuse, but in fact it is only necessary to remember to look at these concepts when you look at the latter two words, you can see its type, such as the essence of the pointer array is an array, the essence of the pointer function is a function , array pointers and function pointers are the essence of pointers. Then we need to understand one thing: the precedence of parentheses is greater than The priority of *, understand what is the use of this? We then looked down:

Int (*p) [];

Int *p[];

Int (*p) ();

Int *p ();

The four definitions above are similar, but they all define different content. First look at the first and second formulas, their similarities are all square brackets, which means that they are all related to the array, and the difference between them seems to be only one parenthesis, but in fact, because the precedence of parentheses is greater than * * p So he's the element for *p p first with [" Union, his type is int* So it's an array pointer. Through the above analysis, it can be easily judged out that the third definition is the pointer function, the fourth formula is a function pointer.

Through the above analysis we summarize a small method of distinguishing them: there is an array of [] , there is a function of () , the pointer is a function or an array of parentheses, without parentheses for the pointer.

Pointer array vs array pointer pointer function vs function pointer

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.