Each memory location that we use to store the data hase an address in computre memory (RAM). Computer Hardware i.e. CPU uses this addess to reference to a particular data item. A pointer is a variable that stores the address of another variable.

A pointer is a variable that represents the location of a data item, such as a variable or an array element. Pointers are used frequently in C, as they have a number of useful applications. For example, pointers can be used to pass information back and forth between a function and its reference point. Pointers provide a way to return multiple data items from a function via function arguments to
be specified as arguments to a given function.

Pointers are also closely associated with arrays and therefore provide an alternate way to access individual array elements.

Within the computer?s memory, every stored data item occupies one or more adjacent memory cells. The number of memory cells required to store a data item depends on the type of data item. For example, a single character will be stored in 1 byte of memory integer usually requires two adjacent bytes, a floating point number may require four adjacent bytes.

Declaring a Pointer

A pointer is declared just like we declare a variable. There is only one difference in declaration is that we add an asterisk * infront of it to indicate that it’s a variable which is a pointer. For example

you can also declare the pointers as

How Pointer work?

Lets write an example to demonstrate the use of pointers.

Now pnum will be having the address of the num variable.

Initializing pointers

It is often a good practise to intialize the variable while declaring. It is very easy to initialize a pointer to the address of a variable that has already
been defined.

You can also initialize the pointer to the default null value.

Here is a simple example that demonstrates the different aspects of the pointer operations.