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