C multiple single line declarations

前端 未结 4 1828
無奈伤痛
無奈伤痛 2020-12-03 06:51

What happens when I declare say multiple variables on a single line? e.g.

int x, y, z;

All are ints. The question is what are y and z in th

4条回答
  •  猫巷女王i
    2020-12-03 07:19

    In your first sentence:

    int x, y, z;
    

    They are all ints.

    However, in the second one:

    int* x, y, z;
    

    Only x is a pointer to int. y and z are plain ints.

    If you want them all to be pointers to ints you need to do:

    int *x, *y, *z;
    

提交回复
热议问题