Type Declaration - Pointer Asterisk Position

后端 未结 5 1075
失恋的感觉
失恋的感觉 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:29

    Stroustrup was asked this and he said (paraphrasing)

    • if you think more C-ish you will say int *a and Employee *pE (so in your head you're thinking "the content of a is an integer")
    • if you think more C++-ish you will say int* a and Employee* pE (so in your head it's "a is an integer pointer")

    You can think however you like, as long as you never declare two pointers on the same line.

    Works for me. I'm an Employee* pE kind of person, but I'm married to an Employee *pE kind of person - my advice would be not to get too worked up about it.

提交回复
热议问题