Software Engineering (Coding tips for c, c++ and SQL)
All about coding tips for c, c++ and SQL. Let's share your idea!
Pages
Home
Programming tips
Thursday, June 16, 2011
Swapping Two Variables without Temp Variable
main( )
{
int a,b;
a=a+b;
b=a-b;
a=a-b;
printf("%a=%d b=%d",a,b);
}
Or
main()
{
int a,b;
a^=b; // a=a^b;
b^=a; // b=b^a;
a^=b; // a=a^b;
}
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment