Re: Swapping

From: Alex Monjushko (monjushko_at_hotmail.com)
Date: 07/16/04


Date: 16 Jul 2004 17:18:47 GMT

In comp.lang.c Julie <julie@nospam.com> wrote:
> Michael wrote:
>>
>> > Please describe (in code) a situation where two variables share the same memory
>> > location.
>> >
>> Dan you need to try stuff for yourself
>>
>> #include <stdio.h>
>>
>> int main(void){
>> int x=10, *p;
>> p=&x;
>> printf("%p, %p\n",(void *)p,(void *)&x);
>> return 0;
>> }

> You need to think a little harder:

> You have two variables: x and p. Are you saying that &x == &p? I sure hope
> not.

That is not what he is saying. You are failing to grasp that *p is a
variable. Perhaps this quote from page 45 of K&R2 will enlighten you:

    "...The increment and decrement operators can only be applied
    to variables..."

This, in my mind, would mean that *p can be considered a variable, at
least part of the time. Technically, of course, *p can hardly be
considered a variable when p does not contain the address of a valid
object.

-- 
Alex Monjushko (monjushko@hotmail.com)


Relevant Pages

  • Re: Swapping
    ... In comp.lang.c Julie wrote: ... > Michael wrote: ... >> Dan you need to try stuff for yourself ... >> int main{ ...
    (comp.lang.c)
  • Re: Swapping
    ... > Michael wrote: ... >> Dan you need to try stuff for yourself ... >> int main{ ... to declared objects, but we can't really infer anything from that. ...
    (comp.lang.cpp)
  • Re: Swapping
    ... > Michael wrote: ... >> Dan you need to try stuff for yourself ... >> int main{ ... to declared objects, but we can't really infer anything from that. ...
    (comp.lang.c)
  • Paciic Pinball Exposition - The First of Many!
    ... show with Michael (Michael Scheiss of the Neptune Beach Amusement ... Dan Fontes - The artist tha created the poster - worked tirelessly ... Joe Sweeney - Bay Area collector who provided a good many of the finer ... Herb Silvers - Herb brough his Retro Pinball "King of Diamonds" ...
    (rec.games.pinball)
  • Re: Paciic Pinball Exposition - The First of Many!
    ... show with Michael (Michael Scheiss of the Neptune Beach Amusement ... Dan Fontes - The artist tha created the poster - worked tirelessly ... Joe Sweeney - Bay Area collector who provided a good many of the finer ... Herb Silvers - Herb brough his Retro Pinball "King of Diamonds" ...
    (rec.games.pinball)

Loading