Does anyone know why Stroustrup\'s style is the placement of pointers as follows? Specifically, what Stroustrup has provided for guidance about this matter?
int
I cannot speak for Bjarne, but tying the asterisk (and ampersand in case of reference) to the type makes sense because being a pointer is semantically part of the type of the variable. The name of the variable is p
and its type is int*
. The name is not *p
and the type is not int
.
It is nearly always possible to avoid multiple variable declarations in a single declaration, so that is not an issue.
In my opinion, this approach is clearer, especially in case of return types:
T*
function(Args...);
T
*function(Args...);