C-language learning notes-pointers reading skills

Source: Internet
Author: User

1. Pointer reading skills: right-left rule

(1) from the undefined identifier in the innermost parenthesis

(2) First look to the right and then to the left

(3) When you encounter parentheses or brackets, you can determine the part type and reverse the direction

(4) Repeat 2 or 3 steps until the end of the reading

Attention:

When you read an array, you must read the number of elements, the type of the element

When the read-out is a function, the parameter and type must be read, and the return value type

When the read-out is a pointer, you must read out the type that the pointer points to, and sometimes you must read the type of the pointer.

①int (*p) (int*, int (*f) (int*));

A, read the non-identifier F, the right to meet the ")" bracket, turn to the left encounter *, so f is a pointer, return to the 2nd step, read right (int *), encountered "(" represents a function, the f is a function pointer to a function, the function parameter is int*, the return value is int type.)

That is, f is a function pointer, and at this point, the F-pointer finishes reading

B, read P not marked, the right to meet the ")" bracket, turn to the left encounter *, so p is a pointer, return to the 2nd step, to the right of the P pointer to the right side of the "(" parenthesis, description is a function, the function has 2 parameters, one for int*, one for the F function pointer, the return value is

That is, p is a function pointer, pointing to two parameters, respectively, int* and function pointer type, return the value of the function pointer of type int.

②int (*p[5]) (int*)

A, read pointer p, to the right, stating that P is an array with 5 elements, each element of type is pointer type, they point to a function, the function parameter is int*, the return value is int type.

B, Comprehensive: p is an array, there are 5 elements, each element is a function pointer, they point to a parameter is int*, the return value is an int function.

③int (* (*P) [5]) (int*);

A, read the pointer p, meet to the right) parenthesis, left *, stating that P is a pointer, part of the type back to the 2nd step, to the right, stating that the P pointer to an array, the array has 5 elements, each element is a pointer, this is a function pointer,

A function that points to a parameter of int* and returns a value of type int.

B, Comprehensive: p is an array of pointers, the array has 5 elements, each element is a function pointer, the function parameter is int*, the return value is type int.

④int (* (*p) (int*)) [5];

A, first p is a pointer to a function, the function argument is int*, and the return value is a pointer. This return value points to an array that has 5 elements, each of which is of type int.

B, comprehensive: p is a function pointer. The function: parameter: int*, the return value is a pointer to the array of 5 int elements.

⑤void (*func (void (*p) (void *))) (void *)

A, Func is a function first: The parameter is P,p is a function pointer, a pointer to a function with a parameter of void*, and a return value of void. The return value is a pointer to a function with a parameter of void* and a return value of void. That is, the return value is a function pointer.

B, in summary, Func is a function, the parameter is the function pointer p, the return value is also a function pointer.

Resources:
Www.dt4sw.com
Http://www.cnblogs.com/5iedu/category/804081.html

C-language learning notes-pointers reading skills

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.