#include<stdio.h>
int main(){
    int a=5,b=10;
    a=a+b-(b=a);
    printf("\na= %d  b=  %d",a,b); 
    getch();
}
Re: explain me the implementation of the expression which swaps the value of a and b. 80 80

That expression is undefined because you're modifying b and also accessing it for purposes other than to calculate the modification between sequence points. The rule is subtle, so I won't expect you to understand it, but do keep in mind that the expression is wrong and doesn't have predictable behavior.

If you fix the expression to be well defined, it's also easier to understand:

#include <stdio.h>

int main(void)
{
    int a = 5, b = 10;
    
    printf("Before: a = %2d  b = %2d\n", a, b);
    a = a + b;
    b = a - b;
    a = a - b;
    printf("After:  a = %2d  b = %2d\n", a, b);

    return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.