Let me start with the basics. First of all, you need to know which variable and how they are used.
Variables are basically memory cells (usually containing some values), and we use some identifier (i.e. variable names) to refer to this memory cell and use the value present in this place.
To understand this better, suppose that we want information from memory cells to be present in some place relative to the current variable. Can we use an identifier to retrieve information from neighboring cells? Not. Since the identifier (variable name) will only give the value contained in this particular cell.
But, if somehow we can get the memory address in which this variable is present, we can easily move to nearby locations and use their information (at run time).
Here the pointers are included. They are used to store the location of this variable so that we can use additional address information if necessary.
Syntax:. To save the address of a variable, we can simply use the & (address) operator.
foo = &bar
Here foo stores the address of the variable bar.
Now, if we want to know the value present at this address?
To do this, we can simply use the * (dereference) operator.
value = *foo
Now, when we need to save the address of the variable, we need the memory in the same way as we need in the case of the variable. This means that pointers are also stored in memory in the same way as other variables, therefore, as in the case of variables, we can also store the pointer address in another pointer.
Abhinav1602
source share