Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - What does int (*p)[3] refer to? Please speak in plain language
What does int (*p)[3] refer to? Please speak in plain language

Pointer to an integer array. (It is a pointer, not a set of pointers, the object pointed to is an integer array, not an integer) The length of the array pointed to must be 3.

< p>For example

int main(void)

{

int (*p)[3];

int x[2 ][3];

p = &x[0]; // ok

int y[2][4];

p = &y[0 ]; // warning y[0] is an array of length 4

return 0;

}

It is the same as an ordinary pointer to an integer or a pointer to an integer The difference between array pointers is that it has requirements on the size of the array, and it also affects the value of the sizeof operator

int main(void)

{

int (*p)[3] = NULL;

int* q = NULL;

printf("%d %d\n", sizeof *p / sizeof(int) , sizeof *q / sizeof(int));

return 0;

}

The output is 3 1