//Swap Two Numbers In Single Statement Without Temp Variable
#include<iostream.h>
#include<conio.h>
int main ()
{
C Program Special Logic Tricks
//Swap Two Numbers In Single Statement Without Temp Variable
#include<iostream.h>
#include<conio.h>
int main ()
{
int a=1,b=2;
clrscr();
a=a+b-(b=a);
cout<<“A: “<<a<<” B: “<<b;
getch();
}
You Can Also Take Input Values For A And B Variables
May Be Your Question Is How This Statement Working ?
a=a+b-(b=a);
First Step a=1+2-(b=1); // Also Assign Values Of a To b
Then a=1+2-1
Now a=2, b=1
OshoGarg is a tech writer from latest tips and tricks blog who share tips on blogger.
Leave a Reply