Amazon Interview Question
Country: United States
Could you tell how x!=x works. I dont know how does the ! operator works in this manner.
It is actually "x = !x" interpret it as " x = (!x)". In C++, the logical date type "bool" is simply "int". In C, you don't have "bool" and should use "int"
That being said, and "int" type is TRUE if it is not zero. e.g.,
int x = -1;
if (x) {
printf("TRUE");
};
prints TRUE unless you set x = 0.
In this code, x = 10, so x is "TRUE" and !x is FALSE which is zero.
Could you tell how x!=x works. I dont know how does the ! operator works in this manner.
Could you tell how x!=x works. I dont know how does the ! operator works in this manner.
Hi not sure about the c code, but if this is to write in java, it will certainly throw error on line
int main(){
int x = 10, y=20; /. //error as /. is invalid character
x=!x; // error , The operator ! is undefined for the arguement type(s) int
y =!x&&!y; //error , The operator ! is undefined for the arguement type(s) int
System.out.println(x +" " +y);
return 0;
}
x=0 y=0
- sravan February 14, 2014