#include<stdio.h>
/*new logic for swapping*/
#include<conio.h>
void main()
{
int x=20,y=30;
printf("nos before swapping are %d and %d\n",x,y);
x=x*y/(y=x);
The problem here is that you're accessing y in an expression where y is
modified. That is undefined behavior.
More precisely, your accessing y for a purpose other than determining a new
value to be stored into y.
The following also accesses y in an expression where it is modified:
y = y + 1;
However, the access in "y + 1" is a necessary operand for computing the value
stored in the assignment. This imposes an order, which makes it well defined.
This one is not defined:
y + (y = 3);
The y on the left of the + is accessed, but that access is not necessary for
the y = 3 assignment on the right. Because it is not necessary, it does not
have to be ordered relative to the assignment, and so we do not know when that
access occurs: before, during or after the completion of assignment to y?
If you write such ambiguous expressions in your C programs, they will be
nonportable between compilers and possibly unreliable even on one compiler.
For instance, if you change some code-generation options such as optimization
settings, the behavior might change.