@Tendua: It does. The result of erroneous code is undefined. It might
work as the coder intended, or it might do something else entirely. It
might even do the intended thing in some cases but fail in others in
the same source file.

Dave

On Jul 14, 12:51 pm, tendua <6fae1ce6347...@gmail.com> wrote:
> @Dave: You said *a ^= *b ^= *a ^= *b violates the sequence point rule
> in swap(). But it's the same as in main function. Why doesn't it
> violates the rule in main() ?
>
> On Jul 13, 1:30 am, Don <dondod...@gmail.com> wrote:
>
>
>
> > 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.- Hide quoted text -
>
> - Show quoted text -

-- 
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