In C/C++, is char* arrayName[][] a pointer to a pointer to a pointer OR a pointer to a pointer?

后端 未结 5 1504
醉酒成梦
醉酒成梦 2020-12-01 10:19

I understood multi-dimensional arrays as pointers to pointers, but perhaps I am wrong?

For example, I though:

char * var = char var[]

5条回答
  •  悲哀的现实
    2020-12-01 10:33

    One of my memorization rules for combinations of * and [] is the signature of main. Works! :-)

    Your dic is an array of 40-element arrays, each element of which is a pointer to char.

    #include 
    #include 
    using namespace std;
    
    template< class Type, unsigned N >
    void tellMeAbout( Type const (&)[N] )
    {
        cout << "Well, it's an array of " << typeid( Type ).name() << ".\n";
    }
    
    int main()
    {
        char  *dic[][40]    = { 0 };
        tellMeAbout( dic );
    }
    

    Using Visual C++ I get ...

    Well, it's an array of char * [40].

    Cheers & hth.,

    – Alf

提交回复
热议问题