the program is : c program to check if two integers entered have opposite or same signs using bitwise operator
when i decalre two varibles of type integer(int)
Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<strings.h>
int main(void)
{
int x=0,y=0;
int result=0;
printf("Enter the first number: ");
scanf("%d",&x);
printf("Enter the second number: ");
scanf("%d",&y);
result=x^y;
if((result&0x80)==0x80)
printf("\nthe two numbers are opposite\n");
else
printf("\nThe two numbers are same sign\n");
return 0;
}
and the result was correct
but when i change the type int of the two varibales into char type as that:
Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<strings.h>
int main(void)
{
char x=0,y=0;
char result=0;
printf("Enter the first number: ");
scanf("%d",&x);
printf("Enter the second number: ");
scanf("%d",&y);
result=x^y;
if((result&0x80)==0x80)
printf("\nthe two numbers are opposite\n");
else
printf("\nThe two numbers are same sign\n");
return 0;
}
the result Always "the two numbers are same sign"
why the result not correct? and i thought that char type can store integer until 255..!