Reading Notes "conquer the C Pointer"-C's statement is interpreted in this way

Source: Internet
Author: User

The best way to interpret C's statement is to read it in English. The truth is very simple, because C language was invented by Americans.

To simplify the problem, const and volatile are not considered here. Next, follow these steps to explain C's statement.

  1. First, focus on the identifier (variable name or function name ).
  2. The derived types (pointers, arrays, and functions) are prioritized from the nearest point of the identifier ). The priorities are described as follows:
    • The arc used to organize the declared content.
    • Used to represent the [] of the array, used to represent the () of the function ().
    • * Used to indicate pointers *.
  3. After the interpretation is complete, the derived types are connected using "of", "to", and "returning.
  4. Finally, append the Data Type modifier (on the left, Int, double, etc ).
  5. People with poor English can explain in Chinese in reverse order.

The number of array elements and function parameters are part of the type. They should be interpreted as attributes of the affiliated type.

For example, INT (* func_p) (double );

1. First, focus on the identifier. INT (* func_p) (double); expression in English: func_p is

2. Because there are Parentheses, here we focus on *. INT (* func_p) (double); expression of func_p is pointer

3. Explain the () used for the function. The parameter is double. INT (* func_p) (double );

Func_p is pointer to function (double) returnning

4. Finally, explain the Data Type modifier Int. INT (* func_p) (double );

The expression in English is func_p is pointer to function (double) returnning Int.

5. finally translated into Chinese: func_p is the pointer to the function that returns the int.

According to this step, you can explain any declaration, for example, the more complex one: int atexit (void (* func) (void ));
The expression in English is: atexit is function (func is pointer to function (void) returnning to void) returnning Int.

Translate to Chinese: atexit is the function that returns int (the parameter is, pointing to the function pointer that returns void without parameters)

Reading Notes "conquer the C Pointer"-C's statement is interpreted in this way

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.