Type Declaration - Pointer Asterisk Position

后端 未结 5 1073
失恋的感觉
失恋的感觉 2020-12-23 17:21

in C++, the following means \"allocate memory for an int pointer\":

int* number;

So, the asterisk is part of the variable type; without it,

5条回答
  •  别那么骄傲
    2020-12-23 17:26

    This is just one of the many irregularities of C's declaration syntax. The type modifier * is part of the type, yet syntactically it belongs to the identifier that's declared.
    The same is true for & and [], BTW.

    See here for what * does besides modifying a type.

提交回复
热议问题