+ 3
auto Vs auto*
I am aware that auto does not hold reference, constantness and volatile until explicitly specified for auto What about auto and auto* Refer code below : I am holding reference of pointer pp into auto p as well as auto* p Both shows same result ... Why so ? Auto and auto* is same ? I thought auto p means pp and auto* p means &pp... Isn't it ? https://code.sololearn.com/c9DBnEl76iJM/?ref=app
1 Resposta
+ 6
There is no difference between "auto" and "auto*" here as compiler is smart enough to deduce the correct type of "p" as a pointer to integer in both cases.
difference between auto and auto* becomes apparent in use cases where you want to make sure that the deduced type should strictly be a pointer.
For example, when you want to declare const pointer
```
const auto* const p = something
```
Or when you want to make sure that the value that you are initialising is a pointer.
```
int c = 10;
auto *p = c // this will throw error
auto p = c // this will work and "p" would be deduced to "int" type
```