Hacker News new | ask | show | jobs
by bregma 2119 days ago
In C,

    char * a;
declares a variable, `a` that, when dereferenced using the `*` operator, will yield an int.

In C++, the same line declares a variable, `a`, of type `pointer-to-int`.

C cuddles the asterisk up to the variable name to reflect use. C++ cuddles it up to the type because it's a part of the type. Opinions don't really differ on whether C-style or C++-style is better, but a lot of cargo-cult programmers don't bother adjusting the style of the code snippet they paste out of Stack Exchange so you see a lot of mixtures.