There is a 4-Byte area in memory, let's say at address 0x2000, this area is called "a"
With the instruction a=5
the compiler (or better startup-code) fills this memory area with the 4-Byte integer 0x00000005 (which is 5 in decimal).
now another variable ptr
is filled with the address of a: ptr = 0x2000.
The pointer contains the address of memory area a
we say ptr
points to a
*ptr
means: the memory area ptr
points to, in this case memory at 0x2000.
So finally *ptr=6
means that the integer/value 6 is filled into the memory area ptr
points to.
Now the memory area at 0x2000 will contain 0x00000006 (decimal 6)
Edit
The modifier const
in int* const ptr
means that the actual value i.e. the adress in ptr
will never change during the execution of the program, it will always point to / contain 0x2000.
This means that an assignment like
ptr = &b;
will fail with a compiler error message.