First, var[i]
is array of type int
. So, each element of that array will take up the size of one int
each. The size of an int
is 4
bytes.
Next, you are using ptr[i]
to hold the address of the elements of var
array. So, the value
of ptr [i]
is increased by 4
for each element.
Here, for better understanding, you should use "%p"
or "0x%x"
format specifier with printf()
when dealing with pointers.
Also, you should change the print statement
printf("\n\nValue of var[%d] = ",i);
to
printf("\n\nAddress of var[%d] = ",i);
as the former is conveying wrong message. Actually the output value is the address for var[i]
. If you want to print the value of var[i]
using ptr[i]
, you can consider using *ptr[i]
.