How can I declare and define multiple variables in one line using C++?

后端 未结 10 1707
抹茶落季
抹茶落季 2020-11-27 11:09

I always though that if I declare these three variables that they will all have the value 0

int column, row, index = 0;

Bu

10条回答
  •  北海茫月
    2020-11-27 12:04

    As @Josh said, the correct answer is:

    int column = 0,
        row = 0,
        index = 0;
    

    You'll need to watch out for the same thing with pointers. This:

    int* a, b, c;
    

    Is equivalent to:

    int *a;
    int b;
    int c;
    

提交回复
热议问题