Today, I read the pointer in the "Interview Guide for C/C ++ programmers". I have understood the pointer problem for a while.
Next, you can perform a test. If you can answer all the following pointer questions correctly, then your C language skills are amazing.
1. int * P;
2. Int ** P;
3. int * P [10];
4. INT (* P) [10];
5. int * P (INT );
6. INT (* p) (INT );
7. INT (* P [10]) (INT );
These seven questions are not very difficult. I believe most readers can answer them.
Answer:
1. A pointer to integer data
2. A pointer pointing to an integer data
3. An array with ten pointers pointing to integer data
4. A pointer pointing to ten Integer Data Arrays
5. For a function (not a function pointer), the function has an integer parameter, and the return value is a pointer to an integer.
6. A function pointer. The function has an integer parameter and the return value is of the integer type.
7. An array with ten pointers. the pointer in this array points to a function. This function has an integer parameter and returns an integer number.
Ah, at that time, I took a sigh of relief, just like a god, but I went on to see one of the following, and I collapsed completely .......
The question is as follows:
Parse the meaning of (* (void (*) () 0. // How is it? Hold it!
Analyze the problem:
I can't hold it anymore. The answer in the book is,
Some microprocessor starts from 0 address, sometimes in order to simulate the situation when the boot, you need to design a C statement to execute the content of 0 address, so there is (* (void (*) () 0.
This statement seems a headache at a glance, but it is quite simple after analysis.
First, when the following function declaration is available:
Void fun (PARAM );
This function is called in the form of fun (PARAM );
The function of the question has no parameters, so it is simplified to fun ();
0 is the entry address of the function, that is, 0 is the pointer value of the function. The pointer function declaration is:
Void (* pfun) (PARAM );
The call format is: (* pfun) (PARAM );
For this question, you can write: (* 0 )();
However, the function pointer variable cannot be a constant. Therefore, we need to forcibly convert 0 to a function pointer. According to the original question, the function pointer prototype of the metafunction is void (*)();
So (* (void (*) () 0) () can be analyzed in this way. First, void (*) () is used to forcibly convert 0 to a function pointer, then, call the function pointed to by function 0.
Typedef can be used to enhance the understanding of this sentence as follows:
Typedef void (* pfun )();
(* Pfun) 0 )();
These two sentences are equivalent to (* (void (*) () 0) (), but this helps to deepen the understanding of this sentence.
CONCLUSION: (* (void (*) () 0) () is the call of the function corresponding to * (void (*) () 0.
Awesome C language pointer... hope to help you grasp the pointer (* ^__ ^ *)