Pointer to array, pointer to function

Source: Internet
Author: User
Pointer to the array: int (* P) [5];

Defines a one-dimensional array pointing to the number of elements whose array element is int type is 5;

It can also be understood as the first element of a two-dimensional array, as if int * P points to the int type, it can be understood as the first element of a one-dimensional array;

It can also be understood as * P as a pointer. The content in the pointer is an array with 5 Int values; * P = A [5];

The "type specifier" indicates the Data Type of the array. "*" Indicates that the variable after it is a pointer type. "Length" indicates the length of the one-dimensional array, that is, the number of columns of the Two-dimensional array, when the two-dimensional array is divided into multiple one-dimensional arrays. Note: The brackets on both sides of "* (pointer variable name)" are indispensable. If brackets are missing, it indicates a pointer array.

P points to the first element a [0] of a two-dimensional array; its value is equal to a, a [0], & A [0] [0];

P + I is equal to a [I];

* (P + I) + J is equal to a [I] [J];

Pointer array: int * array [5];

Indicates a one-dimensional array with int-type pointers;
Pointer to the function: int (* pfun) (parameter );

The above defines a function pointer to the form parameter whose return value is int type and parameter is parameter pfun.

Typedef int (* pfun) (int A, int B );

Pfun fun;

Int A = (* Fun) (2, 3 );

Returns the pointer function: int * Fun (parameter); returns the pointer to the function:

// The function form is set_handler (void (* f )())
// Return the pointer (the return value is void, and the parameter is the void function)
// It can be understood as void (* TMP )();
// TMP = set_handler (void (* F ())
Void (* set_handler (void (* f )()))()
{
Cout <"set_handler" <Endl;
Return F;
}

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.