Pointers – How Pointers work in C++ | Pointers and its Syntax

By | July 26, 2015

Learn about Pointers in Programming and C++. A brief introduction about Pointers

here we learn how the pointers work? What is the Memory  address and what is the syntax of pointers? How a pointer work in our code? A brief introduction of pointers and many more as you want.

In this class i will tell you How a Pointer work in the PROGRAMMING .It is very important topic in C++ and OPP .As every  program consist of one or many variables that take a specific space or memory in the RAM.If we want to see the memory address that take our program we will use the pointers for this propose. We had to see the memory address int our program’s output by using pointers.

Now the Question is that what is the memory address? And how a variable take space in RAM ?



                             The answer is that  when we write a program we declarer  many variables in it and this variables take space in RAM and the answer of other question is that “the data type is specify that how many space is allocated for this variable”.

For Example:)

int   variable name;                               (Take two bytes in RAM)

char variable name;                               (Take one byte in RAM)

float  variable name;                              (Take four byte in RAM)                                and etc…

So lets start the pointers and it Syntax!

First of all i will describe the destination of the pointers.


The variables that is use to store the memory address of another variables in simple words a variable that have some space in RAM and store and retrieve  the memory address of another variable.


The other variables are declared by defined or default data types like int,float char etc…

But the pointers are declared by default as well as user defined data type like classes or structure etc…


the syntax of the pointer is same as the variable but a little difference is that the (*) singe is use in declaration Syntax of the pointer.

                                      data type     *   pointer name;

data type:)           that defines for which type of pointer.

*:)                             that is use to indicate this variable is the pointer and it is use to store the address of other variable.

Pointer name:)   any name which you have to like. The role pointer name is smiler to identifier

For Example:—            int *ptr;          Where int is data type and ptr is the pointer name.

Now i have to write some code to using pointer that is

#include<iostream.h>                      /*  that is the header files or library file which is most important

#include<conio.h>                              to write it in the top of program otherwise the compiler generate an ERROR.*\

void main()                                           //    it is the function where the compiler has start to read the program

{ clrscr();                                              // it is the function to clear the screen

int  a=15;                                             //declaration and instillation  a variable.

int *pt;                                                // declaration a pointer;

*pt=a;                                                // assigning the a to pointer and so it is the pointer that’s why it has to store the address of a’

cout<<a<<“\t”<<pt;                    /*this statement is use to show the value of a s well as the address of a. if we write a very complex

program then we write the (*) singe in cout statement to us to show value for Example  cout<<*pt;   */

pt =a;    ERROR                         // it will be Error because pt is the pointer not a variable that is store the value.




 There is Error if we have to store the address of floating variable into inter pointers it means that we have to store the address in pointer that have same data type otherwise compiler generate an Error Message and yet the pointer has no data type we write the data type in declaration in pointer is only indicate that which variable address is stored in this pointer. In pointer the data type is not act like variable.

i hope today class is helpful to you.keep watching our site for more update and not forgot to register on our site for subscription.

any question then make a comment on us.  Thanks…





Author: Awais Shafique

Hello My name is Awias.I am Student of BSCS in GCUF. I am the Senior Contributor of this website.