C Program to initialize a variable to zero using XOR Operator

Get a integer n and make it as 0 using xor operator

Sample Input 1:

6

Sample Output 1:

0

Sample Input 2:

28

Sample Output 2:

0

Try your Solution

Strongly recommended to Solve it on your own, Don't directly go to the solution given below.

#include<stdio.h> int main() { //write your code here }

Program or Solution

				
			
					
#include<stdio.h>
int main()
{
	int num;
	printf("Enter a number:");
	scanf("%d",&num);
	num=num^num;
	printf("%d",num);
}
			
				
			

Program Explanation

XOR any value with the same produces zero.

Comments