[cs13001] Question regarding pointers.

Mikhail Nesterenko mikhail at cs.kent.edu
Mon Nov 12 16:15:51 EST 2012


> 
> I wanted to ask, what is the difference between the following lines of code?
> 
> *p1 = v1;
> p1 = &v1;
> 
> Do they both have the same meaning? That's what I'm understanding
> right now, they both make p1 point towards the memory address of v1,
> isn't that correct?


The first line takes the value of variable "v1" and stores it to the
memory location to which "p1" points (dereferences pointer "p1");

The second line takes the address of variable "v1" (by invoking
"address of" operator) and assigns this address to pointer "p1" thus
making "p1" point to the variable "v1".

Thanks,
--
Mikhail


More information about the cs13001 mailing list