Preface: Description of Complex Type
To understand pointers, some of the more complex types appear, so I first introduce how to fully understand a complex type, to understand the complex type is very simple, there will be a lot of operators in a type, they also like ordinary expressions, have priority, the same priority and operation priority, So I summed up the principle: from the variable name, according to the operator priority combination, step-by-step analysis. Let's start with a simple type of analysis:
intp;//This is a normal integer variable.
int*p;//first from P, first with the *, so that the P is a//pointer, and then combined with an int, indicating that the pointer to the//content type int. So p is a pointer to the integer//type of data
intp[3];//first from P, first with [], that P is a number//group, and then combined with an int, indicating that the elements in the array are integer//type, so p is an array of integral type data
int*p[3];//first begins at p, first with [], because its priority is higher than *, so p is an array, and then combined with the *, the description//array of elements is a pointer type, and then with the int,//the type of the content pointed to by the pointer is integral type, so// P is an array of pointers that return an integral type of data
int (*p) [3];//first begins at p, first with *, stating that P is a pointer
Then with the [] combination (and "()" This step can be ignored, just for//change the priority), indicating that the pointer to the content is a//array, and then combined with an int, that the elements in the array is//integer. So p is a pointer to a number//group consisting of integer data.
int**p;//first from P, first with the *, said that P is a pointer, then//and then combined with the *, indicating that the pointer points to the element is a pointer, then//and then combined with an int, indicating that the pointer to the element is the whole//type of data. Because the level two pointers and the more advanced pointers are seldom used/ In complex types, we can//do not consider multi-level pointers at most, so we will consider only one level of pointers at a later stage.
INTP (int);//from P, first with (), stating that P is a function and then enters
() analysis, indicating that the function has an integer variable parameters//and then with the outer int, indicating that the function return value is//an integer data
Int (*p) (int);//starting at p, first with the pointer, stating that p is a pointer and then
() binding, indicating that the pointer is pointing to a function, and then combined with the//int (), stating that the function has an int parameter, and then the outermost//int, that the return type of the function is integral, so p is a pointer to a function that has an integer parameter and returns the integer type.
int* (*p (int)) [3];//can skip first, don't look at this type, too complex
Starting with the P, first with (), that P is a function, and then enter//into (), and int, the function has an integer variable//parameter, and then with the outside of the *, the function returns a pointer, and then to the outermost layer, first and [] union, description// The returned pointer points to an array, which is then combined with, say//The element in the array is a pointer, and then combined with an int, indicating that the contents of the//needle point is the integer data. So P is a function that has a parameter of one//integer data and returns a pointer variable that points to an array composed of integer pointer variables.
Speaking of here is almost, our task is so much, understand these types, other types for us is also a side dish, but we generally do not use too complex type, which will greatly reduce the readability of the program, please use caution, the above several types are enough for us to use.
C Pointer Detail (classic, very detailed)