Swapping Two numbers in C without using a third variable

#include <stdio.h>

int main() {
	int x = 2;
	int y = 5;

	// main logic
	x = x + y; // store the sum of two numbers into x
	y = x - y; // store the subtraction of y from new x value into y
	x = x - y; // finally do the same with updated y value

    // printing the output
	printf("x = %d\n", x);
	printf("y = %d", y);
	return 0;
}

Other videos in this series

Back To Home