An Introduction to Pointers in C++ Programming

A pointer, formally called a “derived data type” defines where to get the value of a data variable. It itself, does not store the data but the memory location of the variable.

So, in short, it is a (derived)data type which points to the data of the variable but stores only the memory location of the variable.

The pointer uses the deference(*) operator & the reference/address(&) operator. Some of the stuff we can do using pointers is shown down there.. ;)

int *p1;          /* all of these can be used
int* p2;                  to declare pointers */
int*p3;

int *ptr, a;      //declared pointer and variable
ptr=&a;           //pointer now contains the address of a

cout<<ptr;        //gives the memory location of a
cout<<*ptr;       //gives the value stored at a

It’s very important not to get confused between the &variable, pointer, and *pointer.

&variable is used to assign the pointer an address of the variable, pointer gives the memory location of the variable and *pointer gives the value of the variable.


Also Check Out

Discuss - One Comment

  1. Rajiv Kumar says:

    i like because good definition of topic………………..

Add a Comment

Your email address will not be published. Note marked required (*) fields.

Contact Durofy

For job openings, contact us at jobs@durofy.com | For any other info including business and advertising, contact us at dev@durofy.com

Durofy on Blackberry

Download the Durofy App to get updates on your Blackberry: To download, click here