Amazon Interview Question


Country: United States




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

x=0 y=0

- sravan February 14, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

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

- Ayush February 14, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

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.

- Ehsan February 14, 2014 | Flag
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

- Akshat Goel February 14, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

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

- Anonymous February 14, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

the answer is correct but whats th logic?

- VEDPRAKASHMISHRA0909 March 05, 2014 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

00

- Anonymous February 15, 2014 | Flag Reply
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.

- Ayush February 14, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

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

- Anonymous February 14, 2014 | Flag
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

- Anonymous February 14, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

x=0;y=0

- Abhishek Kumar February 14, 2014 | Flag Reply
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;
	}

- Anonymous February 14, 2014 | Flag Reply
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".

- Anonymous February 17, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

x turns 1 y turns zero

- Kunj February 20, 2014 | Flag Reply
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.

- Yuri April 11, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

x=F5
y=141

- garg.shubhra10 April 18, 2014 | Flag Reply
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

- Anonymous July 25, 2014 | Flag Reply
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;

- Ashok Gowla August 11, 2014 | Flag Reply
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

- vijayedella August 25, 2014 | Flag Reply


Add a Comment
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.

Learn More

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.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More