by bhavesh pandey on December 28th, 2004

bhavesh pandey

Question

Help answer this question below.

What is use of pointer in C++?

Answers. 1 helpful answer below.

  • by Quirkie on January 4th, 2005

    Quirkie

    At the bottom line, pointers or references are used as aliases for an object or variable.

    pointers or references may be used to pass parameters by reference: i.e. to pass the argument itself instead of its value. This allows functions to modify their passed arguments and return additional values, or to avoid copying the argument for efficiency purposes.

    pointers or references must be used when the object itself has no identifier, for example, if it is dynamically created.

    pointers or references to a less specific type must be used to take advantage of polymorphism: that feature of object-oriented languages that allows different objects to provide differing implementations of common functions.

    Pointers and references differ in how they are created and accessed. References are created directly from the object or variable, pointers are created in a number of ways, but typically by using the & operator.
    References are accessed as if they were the object or variable referred to, pointers must be dereferenced using the unary prefix * operator or the a->b operator which is equivilant to (*a).b
    The destination of a pointer may be changed (point elsewhere).
    The desitnation of a reference may not be changed, and must be known from the point the reference is created.

    Pointers are therefore useful for dynamic structures where objects refer to other objects that may change. e.g. in structures such as linked lists and trees.

    No comments. Post one | Permalink

Want to attach an image to your answer? Click here.

Did this answer your question? If not, then ask a new question or create a poll.

You're reading What is use of pointer in C++?

Follow us on Facebook!

Related Ads

ANSWERBAG BUZZ

What s the use of pointer
What s the use of c pointers
How to transfer video onto dvd
What is pointer in c
When to use pointer in c