NVIDIA Interview Question for Software Engineer / Developers






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

a ^= b;
b ^= a;
a ^= b;

- Anonymous August 20, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

nice ...

- jay99 January 13, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I am getting correct output with basic approach...the above approach is not working for me...

int main()
{
	int a = 51;
	int b = 51;

	a = a^b;
	printf("a:%d\nb:%d\n",a,b);

	b = a^b;
	printf("a:%d\nb:%d\n",a,b);

	a = a^b;
	printf("a:%d\nb:%d\n",a,b);

}

- Anonymous December 17, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Output
a:0
b:51
a:0
b:51
a:51
b:51

- Anonymous December 17, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

you made a mistake.
b = a^b; should be b = b^a;

- Anonymous July 13, 2011 | Flag
Comment hidden because of low score. Click to expand.
-1
of 1 vote

right ...thats the best one,...

- jay99 November 24, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
-2
of 1 vote

The above solution would fail when both the elements are equal. The below one is safe.

a = (a==b) | a^b;
b = a^b;
a = a^b;

- Raghu Gandham December 23, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

It wont fail even when both are equal!

- shuby.gupta March 26, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

It wont fail even when both are equal!

- shuby.gupta March 26, 2009 | Flag


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