+ 1
why declare pointer in the first place?
we can print address of any variable using-----cout<<&var;...or there is a difference in printing address using pointer and using ampersand(&) only?
4 Respostas
+ 16
Nobody uses pointers just to print stuff with cout. Pointers have much more important uses.
http://math.hws.edu/eck/cs225/s03/binary_trees/
+ 6
If you just want to print address, then yes it is useless, but if you want for example to have the exact same element stored at different place but those places can be initialized empty, you need pointers
+ 2
No, there is no difference at all. Its just that a pointer is a variable that can store the address so that you may use it later for memory management or other uses.
You can change the address of a pointer variable to something else (Some other variables' address), but you cannot do so with the addressof operator (&a), as the value returned is an rvalue.