## Amazon Interview Question

• -1
of 1 vote

Country: United States

Comment hidden because of low score. Click to expand.
2
of 4 vote

x=0 y=0

Comment hidden because of low score. Click to expand.
0

Could you tell how x!=x works. I dont know how does the ! operator works in this manner.

Comment hidden because of low score. Click to expand.
0

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.

Comment hidden because of low score. Click to expand.
1
of 1 vote

x=0 y=0

x = !x -> x = 0
y = !x&&!y -> y=0

Comment hidden because of low score. Click to expand.
0

Could you tell how x!=x works. I dont know how does the ! operator works in this manner.

Comment hidden because of low score. Click to expand.
0

the answer is correct but whats th logic?

Comment hidden because of low score. Click to expand.
1
of 1 vote

00

Comment hidden because of low score. Click to expand.
0
of 0 vote

Could you tell how x!=x works. I dont know how does the ! operator works in this manner.

Comment hidden because of low score. Click to expand.
0

! of zero is always returns true i.e. 1 and ! of any non zero value returns 0 i.e. False.

Comment hidden because of low score. Click to expand.
0
of 0 vote

x!=x (x is not equal to x) is a boolean expression which evaluates to false but it is not stored in any other variable.

x=!x (the value of not x is stored in x), here ! is logical not operator, since x=10, x is considered true in C now !x is false which evaluates to 0 in C

Comment hidden because of low score. Click to expand.
0
of 0 vote

x=0;y=0

Comment hidden because of low score. Click to expand.
0
of 0 vote

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;
}``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

! of any nonzero value gives "ZERO".so x will be "ZERO".And for y,as first operand is 0
total expression evaluvates to "ZERO".so y will be "ZERO".

Comment hidden because of low score. Click to expand.
0
of 0 vote

x turns 1 y turns zero

Comment hidden because of low score. Click to expand.
0
of 0 vote

Will print out
x = 0 y = 0

! is NOT or invert operation.

Negation of Zero = 1
Negation of Non zero number = 0

NOT operation on any number > 0 will yield zero and vice versa.

Comment hidden because of low score. Click to expand.
0
of 0 vote

x=F5
y=141

Comment hidden because of low score. Click to expand.
0
of 0 vote

x=!x // x=0 as negation of true is false
y=!x&&!y //! has higher precedence it will evaluate first so !x is 1 and !y is 0 then using logical and operator for values (1 and 0) we get Zero which is assigned to y finally.
So the result would be x=0 and and y=0

Comment hidden because of low score. Click to expand.
0
of 0 vote

output will be x=0,y=0;
x=!x it means x=0;
y= !x && !y ; !x=1 and !y=0 then 1&& 0; means y=0;

Comment hidden because of low score. Click to expand.
0
of 0 vote

``x =!x;-->x=0``

``y =!x&&!y;--->y=1&&0-->y=0``

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

### Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

### Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.