pointers in c++

hi, I have just started learning C++ and have a doubt on the use of pointers which may be really basic. My question is what is the real application of pointers?
Because when you assign a pointer to an array say :
int *p;
int a[8];
p=a;

when you want to reach any member of the array you can always read it with a[i] so why use pointer and access it with *(p+i)?

thanks in advance
Pointers are used:
1) With pointer-to-base-objects to use polymorphism.
2) To point to dynamically allocated objects
3) To pass C-style arrays in functions (there is no way to pass them by value and passing by reference have clumsy syntax and rarely needed)
4) As iterators to C-arrays and maybe other trivial contiguous containers (std::array and vectors iterators are often represented as simple pointers)
5) To gain access to object you do not own (so you store pointer to it instead storing it inside)
6) Other applications.
^ Read that and remember it forever.

Would get rid of all of the "C++ was so hard because of pointers". Well why are you using them?!? LB you need to code a bot so it posts that link whenever someone mentions the word pointer and C++ anywhere on the internet.
/rant
>
In C, when a parameter, struct member, or any variable needs to be "optional" - that is, it may either have a value or not have a value, the solution was to use a pointer. If the pointer was null, the value did not exist. If the pointer is not null, dereferencing it gives you the value.

In modern C++, there will eventually be the std::optional class (nearly identical to boost::optional) which encapsulates this behavior in a safe way. It's not in C++ yet, unfortunately, but you can use Boost or replicate it yourself until then.
http://www.lb-stuff.com/pointers


Repeat:
Please try to understand the difference between value semantics and reference semantics.
std::experimental::optional<T> holds an optional (non-polymorphic) value of type T.

"A program that necessitates the instantiation of template optional for an lvalue reference or rvalue reference type ... is ill-formed."

The grotesque std::experimental::optional< std::reference_wrapper<T> > over the straightforward T*, anyone?
http://www.cplusplus.com/forum/beginner/166841/#msg839293


Repeat:
'The World’s Dumbest Smart Pointer' has finally made it into the Library Fundamentals 2 TS. std::experimental::observer_ptr<T> is a sane drop-in replacement "for near-trivial uses of bare/native/raw/builtin/dumb C++ pointers."
http://www.cplusplus.com/forum/beginner/166841/#msg839434
when you want to reach any member of the array you can always read it with a[i] so why use pointer and access it with *(p+i)?


You can also access it with p[i]. In fact, *(p+i) is essentially just syntactic sugar for p[i].
In fact, *(p+i) is essentially just syntactic sugar for p[i].
It is backward: subscripting is defined in terms of pointer arithmetic
Standard wrote:
The expression E1[E2] is identical (by definition) to *((E1)+(E2))
thank you guys. It was really helpful
Topic archived. No new replies allowed.