Decode School

Decode School - The School for Problem Solvers

Welcome to my blog. Subscribe and get my latest blog post in your inbox.

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

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.