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

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

Why do most C programmers name variables like this:

int *myVariable;

rather than like this:

int* myVariable;
12条回答
  •  闹比i
    闹比i (楼主)
    2020-11-22 09:21

    Consider

    int *x = new int();
    

    This does not translate to

    int *x;
    *x = new int();
    

    It actually translates to

    int *x;
    x = new int();
    

    This makes the int *x notation somewhat inconsistent.

提交回复
热议问题