Santos
Posts : 23 Join date : 2009-03-11 Age : 37 Location : Kathmandu,Nepal
| Subject: Swapping variables in C Thu Apr 02, 2009 10:06 am | |
| This is a post on NNF by user viper and edited by other users.I have posted it here because I found it impressive although I haven't compiled it somebody plz. .... normally to swap a n b you would void swap(int a, int b) { int temp; printf("val of a =%d and val of b=%d",a,b); temp=a; a=b; b=temp; printf("val of a =%d and val of b=%d",a,b); } u can do this without allocating the variable temp as void swap(int a, int b) { printf("val of a =%d and val of b=%d",a,b); a= a + b; b= a - b; a= a - b; printf("val of a =%d and val of b=%d",a,b); } | |
|