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

前端 未结 5 1427
南方客
南方客 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 16:38

    Because generically speaking they are not the same. The first one defines one element array of SomeType and the other defines pointer to SomeType.

    The first allocates memory for that one element, the other does not.

    In general: sizeof(SOmeType[1]) != sizeof(SomeType*).

提交回复
热议问题