Array pointer and function pointer

Source: Internet
Author: User

Pointer array, array pointer, function pointer:

1. pointer array: the data items of the array are pointers. The most common is the string pointer array. See the following example:

Char * cities = {"Jinan", "Qingdao", "biejing", "Shanghai", "Wulumuqi "};

Note the initialization method of pointer array: Put the five string constants in the Data zone, and cities only store these five pointers.

Comparison with 2D data:

Char cities2 [] [9] = {"Jinan", "Qingdao", "biejing", "Shanghai", "Wulumuqi "};

This looks very similar to the pointer array. The occupied space is quite different: the pointer array contains actual space, and each string in the two-dimensional array occupies nine characters.

2. array pointer: pointer to an array. This can distinguish between function pointers and pointer arrays. For example:

INT (* pint) [5]; // array pointer

INT (* pfunc) (INT); // function pointer ----------- is similar in shape? Is the name very similar?

Array pointer type (data type): int (*) [5], the following code will give an error prompt:

Int A [5] = {1, 2, 3, 4, 5 };

Pint = A; // error message: Type incompatible int (*) [5] to int *

Pint = & A; // correct, reflecting the concept of pointing;

Generally, array pointers and two-dimensional arrays are used together:

Int AA [3] [5] = };

Pint = AA;

3. function pointer: pointer to a function.

Its Type: int (* pfunc) (INT); ---> int (*) (INT)

Function pointers are mainly used as the address for passing function parameters. But it can also be used as the return value.

Parameter: int signal (INT Sig, void (* func) (INT ))

Return Value: void (* signal2 (INT). signal2 parameter is int, return value is void (*) (INT)

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.