[C language] pointer array _ array pointer _ function pointer _ function pointer array _ pointer to function pointer array

array of pointers | pointer to array | pointer to function | array of function pointers | pointer to array of function pointers

  how about it? Does the title dazzle you before you even browse the article? (laughs) Don't be afraid, look at the common feature of these phrases, that is, they all have one word: pointer. As the name suggests, this knowledge is of course closely related to the pointer, so let's see the power of this pointer...

array of pointers

  What is an array of pointers? is it a pointer? Or an array?
  In fact, I have a little way to analyze this kind of problem and share it with you:
  in Chinese, we have learned that in general, modifiers are in front of the modified words (I am not good at Chinese, so everyone understands it ( lol))
  Then the pointer array is that the pointer is modifying the array, where the array is the modifier, and the pointer is the modifier.
  
  It is not difficult to understand that an array of pointers is actually an array: several pointers are stored in this array.
  It is written as follows:
  write picture description here

array pointer

  I believe that after my analysis above, my friends should have a certain idea of ​​​​analyzing this knowledge point.
  
  That's right, this array pointer is actually a pointer: it's a pointer to an array that holds several elements.
  Array pointer for short, it is written as follows:
  write picture description here
  
  However, it is obviously not enough to master this analysis method, because in the actual application process, the code is not in Chinese, but in the same form as the picture above.
  So how to analyze whether it is an array or a pointer?
  Here I have another method for analyzing the problem, which I will share with you here:
  
              analyze one by one through operator priority.
  
  This sentence is extracted from this method, and I will not buy it. I will show you how to use it. This method analyzes the above knowledge points:

    int (*p)[]

  Because of the priority of the parentheses, we analyze this code from the inside out, p is first combined with the '*' sign, indicating that p is a pointer variable, and then the pointer p is combined with the brackets, indicating that p points to an array, Finally, int modifies the previous code, indicating that the array pointed to by p stores integer elements.
  This method can easily analyze this difficult knowledge point very thoroughly. Finally, we summarize the analysis just now:
  this statement is to define a pointer to an array that stores several integer elements.

function pointer

  With these two methods of analyzing the problem, let's take a look at this knowledge point. Obviously, the function is modifying the pointer . Then the function pointer is actually a pointer: it is a pointer to a function
  It is written as follows:
  write picture description here
  Let's analyze how it is constructed:
  
  Because of the parentheses priority, we still start from the inside, pAdd and ' * ' Combined, indicating that pAdd is a pointer, and then combined with the outer layer, indicating that this is a function, the return value of the function is of type int, and the two parameters of the function are of type int
  Finally, let's summarize:
  this statement is defining A pointer to a function, the return value of this function is of type int, and the two parameters of this function are of type int
  
  What about? Is this method of analysis easy to use? Then let's take a look at the following knowledge points, everyone must hold on!

array of function pointers

  Array of function pointers? ? ? What is this?
  We first use the analysis method just now to determine whether it is a function or a pointer or an array? Both the word function and the word pointer
  here are modifying the array , so we can be sure that this is an array. This is an array that stores function pointers.   It is written as follows:   Let's analyze its structure: Because of the parentheses precedence, we start the analysis from the inside, because the square braces have higher precedence than ' * ', p is first with the middle The parentheses are combined into an array, and then combined with ' * ', indicating that the pointer element is stored in the p array, and then combined with the outer layer, indicating that the pointer element in this array points to a function. The return value of the function is of type int, and the two parameters of the function are of type int.   Finally, to summarize: this statement defines an array that stores several pointers to functions, and the return value of the function pointed to by this pointer is of type int , the two parameters are of type int

  write picture description here

  
  

  

pointer to array of function pointers

  It's not easy to see the little friends here. If the things in front of you don't confuse you, please allow me to give you a thumbs up. It's really not easy to understand. But don't be too happy, there is one last very confusing knowledge point, let's see it!
  Is it a little scary to see so many modified words in the front? Yes, it is not difficult to know that using the previous analysis method, this is a pointer, it is a pointer to an array of function pointers: a pointer points to an array of function pointers!
  It is written as follows:
  write picture description here
  Finally, I will take you to analyze the structure of this statement:
  because of the parentheses, we analyze from the inside out, pp is combined with ' * ', indicating that pp is a pointer, and then in the outer layer, because the square brackets take precedence The level is higher than ' * ', the pointer pp is combined with the square brackets, indicating that the pointer pp points to an array, and the ' * ' modification indicates that the pointer element is stored in this array, and it retreats to the outermost layer, which is the same as the outer function pointer type (int (*)(int, int)) combination, indicating that this array stores a pointer function, the function pointed to by the pointer inside, the return value is int type, and both parameters are int type

  After learning this, we must have a different understanding of pointers, right?
  Come on, let's work together

The full text is over, thank you for browsing

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326770184&siteId=291194637