What makes pointers different to normal variables, and what is the point of using them over normal variables? I want a long and detailed description please :D

7 Years
Discussion Span
Last Post by K0ns3rv

There are literally hundreds of tutorials about pointers online. I'd recommend reading as many as you can and asking here if you have specific questions.



There are a few big benifits of pointers and references.

For example if you have a function that calculates the result of a x^2 equation you would want it to return both the roots.
This can be achived by passing a reference or pointer to variables that will contain the roots after the calculations.

Like such:

Int calculate(float p, float a, float q, float& x1, float& x2);

Other uses includes:
Creating a pointer and later telling what to point at using the new keyword, called dynamic memory.
Having one pointer which can point at two diffrent variables which changes during runtime.
Avoiding passing big data structures as arguments( copying isn't good).
Creating linked lists.
In 3d graphic pointers are often used when swapping between the back and front buffer.

Here's more material:
Pointers @ cplusplus.com

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.