Why is the asterisk before the variable name, rather than after the type?

后端 未结 12 1671
时光取名叫无心
时光取名叫无心 2020-11-22 08:53

Why do most C programmers name variables like this:

int *myVariable;

rather than like this:

int* myVariable;
12条回答
  •  死守一世寂寞
    2020-11-22 09:25

    That's just a matter of preference.

    When you read the code, distinguishing between variables and pointers is easier in the second case, but it may lead to confusion when you are putting both variables and pointers of a common type in a single line (which itself is often discouraged by project guidelines, because decreases readability).

    I prefer to declare pointers with their corresponding sign next to type name, e.g.

    int* pMyPointer;
    

提交回复
热议问题