The pointer seems to be much bamboozled but reality is that help us in making our task easier. Pointer points out the place of a certain element in the memory. For instance, there is a container which tells the place of other container. In that container, there is written 23. So, the container which has number 23 is known as integer. The container which tells the address is called pointer.
The language rules of pointer are complicated because pointer let us know the place and also the value piled up in it. For the announcement of pointer * is used. It is important to know that where you use the *, the next word will be affirmed as a pointer. The correct way of defining a pointer is given here:
Pointer can be used either for understanding the place in memory or for granting the real position to new variables. For assigning the place to other, you have to write the pointer name without mentioning the *. For getting entrée to real memory, you have to use *.
If you want that your pointer gives reference to other variable then you have to know its location in the memory. For hiring the location in memory, just use the & after the name of variable. It is known as address operator.
using namespace std;
p = &y;
cout<< *p <<"\n";
“cout” yield the assessment in y. “Y” is used as an integer whereas p is its pointer. With the help of &, the place in memory of y is stored in a pointer. The asterisk assigns value in the place whereas none * tells the place in memory.
You can start pointer with free memory. It permits distribution to array memory which is used for making the formation of linked lists. If you want to get free memory, “new” is used. Its structure is as given below:
For addressing towards the location in memory ptr is used. It tells the size int (the reason is that variables have many sizes, and dissimilar number of bytes). Always remember that if you have pointed the memory then it will not be used for others. So, it is important to use a sensible coding that will open the memory after using it. “delete” is used as machinist which makes the memory free after using it. The syntax is:
At the end, you have to erase the pointer by giving it value of 0. In this way, the pointer will gain the position of null. It will prevent you from doing anything wrong. Whenever you will perform some erroneous, you will get an instant alert.