Difference between two declarations involving a pointer and an array

后端 未结 6 1247
臣服心动
臣服心动 2020-12-18 11:45

What is the difference between int *a[3] and int (*a)[3]?

6条回答
  •  孤城傲影
    2020-12-18 12:10

    It seems like your asterisks are lost in the formatting...

    int *a[3]
    

    declares an array of 3 int*.

    int (*a)[3]
    

    declares a as a pointer to a vector of ints. This is really not much different from any other pointer, it just points to a somewhat more complicated type.

    int foo[3];
    int bar[3];
    int (*vp)[3];
    vp = &foo;
    (*vp)[0] = 0;
    

提交回复
热议问题