3 ms·
Because the * belongs to the variable, not the type. It's more clear with this example, which declares two variables at the same time: int *foo, bar; This
by lokedhs 9y ago
Because the * belongs to the variable, not the type.
It's more clear with this example, which declares two variables at the same time:
int *foo, bar;
This declares foo as a pointer to int, and bar as an int. The following, written in the style you suggest, do the same thing but can be confusing, since a casual reader might think that this declares both foo and bar to be pointers to int:
int* foo, bar;
Someone else commented that C's declarations are designed to look the same as how they are used. This is true, and explains why arrays are declared the way they are, where the brackets come after the variable name: int foo[10]