What's the difference semantically and technically between doing struct user* bob
and struct user *bob
?
According to some sources it's called thing* bob
or thing** bob
, which makes sense because it is of type struct*
(or pointer to struct)
On the other hand we can also do thing *bob
or thing **bob
Take the example program:
struct user
{
int age;
int *p_age2;
};
int main()
{
struct user bob;
struct user* p_bob = &bob;
I am not sure if it's purely a matter of coding style or if there is actually a slight difference somewhere. I'd be interested to hear why one or the other could make more sense. Another important thing to note is that struct tags and struct variables can have no type prior to them sometimes so maybe user* would make more sense then.
What's the difference semantically and technically between doing
struct user* bob
andstruct user *bob
?
To the compiler, none, though the latter syntax is more clear, since the line struct user *bob, alice;
will declare bob as a pointer to struct user
and alice as a struct user
.