What\'s the difference between the types of bar1
and bar2
?
int foo = 10;
auto bar1 = &foo;
auto *bar2 = &foo;
As others said, they'll generate the same code. The asterisk is line noise (and makes it harder to switch from raw pointers to smart pointers if, for example, &foo
is ever replaced by get_foo()
). If you want to be explicit, then by all means, be explicit; but when you're using type inference, just let the compiler do its job. Lack of asterisks does not imply that an object isn't a pointer.