Why pointer (*) and array ([]) symbols are bound to variable name and not to type in variable declaration?

后端 未结 2 1456
清歌不尽
清歌不尽 2021-01-14 07:30

There\'re a lot of questions on SO about details of pointer and array declarations in C (and C subset of C++).
I\'m more interested in why.
Why

2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-14 07:57

    Why do we have to put *, [] in front of every variable when we declare several pointers/arrays in a row?

    The answer would be: explicit is better than implicit. In such a case we can even declare different types on the same row, int *a, *b, c; and so on, in another case it would be too messy. The same true for the second question.

提交回复
热议问题