C Pointer Summary 3

Source: Internet
Author: User


C Pointer Summary 3


Now summarize the pointers for a higher level of usage, where pointers to functions have been introduced separately in my blog post, which will add a few points and now describe the use of other pointers.
First introduce several traps:
int f () [];
int f[] ();
Both of these statements are illegal, and if someone asks what the two statements mean, we should say this wrongly, without hesitation, that the blogger has pondered the meaning of these two statements, and now it is ridiculous to think about them.
Now add a few points to the pointer to the function:
For example:
Int (*PF) (int) =&f;
Now that a function pointer is created and initialized to the function F, the & operator of the initialization expression is optional, because the function name is always used by the compiler to turn it into a pointer to a functional. The & operator only shows the tasks that the compiler implicitly performs.
The function name is first converted to a function pointer that formulates the position of the function in memory.
In addition to the function pointers, one important usage is the conversion table. Is the calculation of generics using void.
my blog void and generic calculations have clearly illustrated this issue.
The last high-level application instance of the pointer is the use of command-line arguments and has been introduced.
The keyword const is now introduced.
Const can create array constants, pointer constants, and pointers to pointer constants.
A pointer to a constant is usually used as a function parameter to indicate that the function does not reference the pointer to modify the data.
void Show_array (const double *ar, int n)
There are some rules for pointer assignment and const Note that it is legal to first assign the address of a constant or very data to a pointer to a constant.
int rates[10]={0};
const double *p=rates;
However, only the address of a very large amount of data can be assigned to a normal pointer:
const double A;
p=a; illegal.
Double *p=rates; legal
Declares a pointer to a fixed address:
Double *const p=rates; this pointer points to the address of the first element of the array and cannot be changed.
You can declare by using two const:
const double *const p=rates; You cannot modify the value of a pointer and what the pointer points to.

C Pointer Summary 3

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.