The difference between pointer arrays and arrays of pointers

Source: Internet
Author: User
Tags define function

1: Array of pointers: the elements inside this array are all pointers ;

Such as:

int a[] = {1,2,3,4,5};

int *p[] = {&a[0],&a[1],&a[2],&a[3],&a[4]};//All elements are addresses

2: Array Pointers:

A pointer to an array is called an array pointer

int (*p) [4]; The array pointer is the row pointer; The P pointer points to an array of 4 values of type int

3: Function pointer:

A pointer to a function

The return type is the return type of the int function; parameter is the parameter type of the function fun

Int (*fun) (int x, int y);

Such as:

/* p is a function pointer */
Assignment value:

Int (* p) (int, int) = & Max; & can omit Max as a function

Use:

P (A, B);//equals Max (b)

4: pointer function:

The pointer function returns an address;

int * Fun (int x)

{

int *p = &x;

return p;

}

5: Use of function pointer arrays

/* Define function pointer array variable Fun_array
(int,int) a list of functions corresponding to the function pointer array that points to 4 function names
*/
Int (*fun_array[4]) (int,int) = {Add, sub, mul, Div};

int result = Fun_array[0] (i,j); A function that represents the No. 0 array element is called the Add function

The difference between pointer arrays and arrays of pointers

Related Article

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.