Hacker News new | ask | show | jobs
by int_19h 3460 days ago
The reason why people don't usually run into this is because C tries really hard to decay your arrays to pointers to first element, so there are very few cases where it actually comes up - sizeof(array) and &array are some of the few. On top of that, writing down the type of such an array is not exactly obvious, and requires parentheses:

    int (*p)[10];
This all is much more interesting in C++, because there, in conjunction with references, this lets you write functions that take arrays as arguments and know their length. Like so:

    template<size_t N>
    void foo(const int (&a)[N]) {
        for (size_t i = 0; i < N; ++i)
            cout << a[i];
    }

    int a[10];
    foo(a);