One thing that I always found counter-intuitive in the C programming language is how, when defining pointer variables, we don't really declare the type beforehand, but have to put the * before each variable to make it a pointer like this:
int *a, *b;
Instead of doing
int* a, b; // Results in b being an int, not an int*
This can be counterintuitive especially for beginners, when they see a declaration like
int* a;
they might think that just like when you simply do int a;
you're declaring the type (int*
) and then the variable name. That's why we tend to put the * after the space, so that one realizes it has to be put before each variable name, but still why not defining it so that it would work the way all other types do? Especially considering that the type is referred to as int*
. Was is out of consistency with arrays, where they wanted to leave the []
after each variable name so that they could give a different size to each?