what is mean of this declaration int (*a)[2]?

I saw a declaration like this:

int (*a)[2]

What does this mean? Is this a two dimension array? How should I use it ?

Thanks.
Probably be easier to just mention it is a pointer to an array of 2 integers and not an array of 2 pointers to integer
Thanks, both of you.
So generally, if I declare:

int a[2];

now &(a[0]) is the pointer to the array of 2 integers. It is same as "a" in int (*a)[2] ?

Thanks.
int a[2];

now &(a[0]) is the pointer to the array of 2 integers. It is same as "a" in int (*a)[2] ?


No. a[0] is an int. Taking the address of an int gives you a pointer-to-int, not a pointer-to-array-of-2-int.

1
2
3
4
5
6
7
8
9
10
11
12
13
// http://ideone.com/ejPK6l
#include <iostream>
#include <typeinfo>

int main()
{
    int a[2];

    std::cout << typeid(a).name() << '\n';
    std::cout << typeid(a[0]).name() << '\n';
    std::cout << typeid(&a[0]).name() << '\n';
    std::cout << typeid(&a).name() << '\n';
}
Output from VC++ (GCC tends to be a little more cryptic)
int [2]
int
int *
int (*)[2]
Thanks very much, now I think I understand the difference.
Topic archived. No new replies allowed.