Why use SomeType[1] instead of SomeType* as last member in structs

前端 未结 5 1418
南方客
南方客 2021-01-26 15:59

I saw in the code next statement:

SomeType someVar[1];

Later someVar is used as a pointer to SomeType. Why would one

5条回答
  •  再見小時候
    2021-01-26 17:01

    SomeType someVar[1];
    

    someVar is an array of type SomeType with 1 element.

    SomeType* someVar;
    

    someVar is a pointer (dangling still, you didn't point it to anything yet) of type SomeType.

    And you can use the name of an array on its own as a shorthand for a pointer to the first element of that array.

    Will Dean

提交回复
热议问题