What is meant by this act? (int (*) [10])

I came across the following roles:

(int (*)[10])

      

In my opinion it is "pointer to pointer to int". Suppose the following array declaration:

int array[10];

      

Then I would assume it &array

has the type(int (*)[10])

Is it correct?

+3


source to share


4 answers


In my opinion, it is "pointer to pointer to int".

Not. Its a pointer to an array of 10 int

s.



Then I would assume it &array

has the type(int (*)[10])

Yes. Your guess is correct. &array

is the address of the array array

and has a type int (*)[10]

.

+4


source


It is a pointer to an integer array of size 10, not a pointer to a pointer to int.

For example, when you pass the type

 char arr[20][10]

      



to the function it decays to inject char (*) [10]

Since the compiler needs to know no columns to efficiently convert a 2d array to linear in memory, this is not the same as int **.

+6


source


Here's a training example that matches your observation (compiled with no warnings):

int array[10]; /* an array of 10 ints */
int (*ptr)[10] = &array; /* a pointer to an array of 10 ints */

/* a function which receives a pointer to an array of 10 ints as param */
int myfunc (int (*param)[10])
{
    return 10;
}

int main(void)
{
    /* a pointer to a function that accepts a pointer to an array of 10 ints as parameter and returns an int */
    int (*func)(int (*)[10]);

    func = myfunc; /* no cast needed. The objects are of the same type */
    /* func = (int (*)(int (*)[10])) myfunc; */ /* with cast */

    (*func)(ptr);  /* function pointer called with ptr parameter */
    return 0;
}

      

+2


source


its a pointer to an array of 10 integers.

0


source







All Articles