Now we have the ability to store the address of a variable
in a separate variable know as pointer variable and through that variable we
can easily access the value of other variable whose address it is storing.(If
you found this statement confusing you probably should give another good read to
this article.)
In this article we would try to break inside the variable
using various ways.
Let’s take a look at the following code:-
- #include<stdio.h>
- void main()
- {
- int var;
- int *p;
- var=5;
- p=&var;
- }
After the execution
of the above code this is how your machine will allocate memory space for both the variable var and p and put 5 inside var and address of var which happens to
be 1000 inside p and as p is a pointer variable it acts as if the variable p is
pointing towards the variable ‘var’.
While in
reality it is just a variable (a space allocated inside the memory of your machine)
that is why the pointer variable p will also have an address.