Sunday, June 1, 2014

Is there any way to do swapping of two variables in one instruction

Is there any way to do swapping of two variables in one instruction i.e in one line only ? (Note : weknow that we can swap two variables without using any temporary variable using with 2 methods(XOR and summation method) but that would require three instructions ,but i want solution in only one instruction.

ans:

int main() { int num1 = 10; int num2 = 20; //swap the numbers num1 = num1 + num2 - (num2 = num1); //swapped return 0; }

copied from a site, check whether its working or not ...

Ethernet and more

Ethernet is a protocol under IEEE 802.33 standard User Datagram Protocol (UDP) UDP is a connectionless transport protocol. I...