3 ways to swap two numbers in C language

3 ways to swap two numbers in C language

//1

int a = 1;
int b = 2;
int tmp = 0;

tmp = a;
a = b;
b = tmp;

//2
int a = 1;
int b = 2;

a = a + b;
b = a - b;
a = a - b;


//3
int a = 1;
int b = 2;

a = a ^ b;
b = a ^ b;
a = a ^ b;

Comments

Popular posts from this blog

Python Receiving and parse JSON Data via UDP protocol

ubus lua client method and event registration code demo/example