Definition and usage of the C pointer

Source: Internet
Author: User

Some common definitions of pointers are summarized as follows:

Int F; an integer variable

Int * F; a pointer to an integer.

Int const * F; F is a pointer to an integer constant. You can modify the pointer value, but cannot modify the value it points.

Int * const F; F is a constant pointer to an integer. the pointer is a constant and its value cannot be modified. However, you can modify the value it points.

Int const * const F; the pointer itself or the value it points to is a constant and cannot be modified.

Int * F (); you can view * F () as an expression, which is actually int (* F (). (* F () as a whole. It is declared as an int. * F () => int, then f () (because the function call operation has a higher priority than the indirect access operator) is a pointer to an int type. F () is a function, so the return value type of this function is a pointer to an integer.

INT (* f) (); F is a function pointer, and the function to which it points returns an integer.

Int * (* f) (); F is a function, and the return value of the function to which it points is an integer pointer.

Int f [10]; F is an array, and its element is int.

INT (* f) [10]: F is a pointer pointing to an array containing 10 int values. F is also called an array pointer.

Int * f [10]; [] has a high priority. f [10] is an array and Its element type is a pointer to an int.

INT (* f []) (INT, INT); F is an array, and the elements of the array are pointers. Since () is followed, F is a function pointer array. The Return Value of the function is int.

Int * (* f []) (INT, INT); the only difference from the above is that the return value of the function is an integer pointer.

Function pointer:

Int F (INT );

INT (* PF) (INT) = & F; equivalentINT (* PF) (INT) = F;

During initialization, & is optional because the compiler always converts the function name into a function pointer when it is used. & The operator only shows the tasks that the compiler will implicitly execute.

References:

Pointers on C, kentha. reek

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.