To make it into valid code, break it into three operations:

void swap(int *a, int *b)
        {
          *a ^= *b;
          *b ^= *a;
          *a ^= *b;
        }

On Jul 12, 3:25 pm, Dave <dave_and_da...@juno.com> wrote:
> @Tendua: The statement  *a ^= *b ^= *a ^= *b violates the sequence
> point rule, which says that results are undefined if a variable is
> assigned more than one value between sequence points.
>
> Dave
>
> On Jul 12, 3:15 pm, tendua <6fae1ce6347...@gmail.com> wrote:
>
> > # include <stdio.h>
>
> > void swap(int *a, int *b)
> >         {
> >         *a ^= *b ^= *a ^= *b;
> >         }
>
> > int main()
> >         {
> >         int a=45, b= 56;
> > //      a ^= b ^= a ^= b;
> >         swap(&a,&b);
> >         printf("%d %d",a,b);
> >         }
>
> > This code gives output 0, 45
> > While if we uncomment the line in main function and don't use swap
> > function, we get correct value. Explain why the same line when used in
> > swap function gives such output.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to