HITEQUEST
technical interview Q & A for high-tech professionals
 
 
Interview Questions
Electronics Hardware
Computer Software
General questions
Brain teasers

Resources
Resume and interview
How to get a job in Silicon Valley
How much are you worth on market?
Do you need an agent?

Break time stories
Tomato company

About Hitequest
About Hitequest
Join us
Home page

 
 
 
 
 
 
   

 
=Computer Software Questions=

     
   

Q:
There are two integers a and b. How to exchange the contents of them without using a third one?
 
 
 
 
 
 
 
 

A1: submitted by Anonimous1

The answer is to do the following:

int a = 7, b = 4;
b = a * b; // b = 28
a = b/a;   // a = 4
b = b/a;   // b = 7


 
 
 
 

A2: submitted by jhudzik

This will work:

  a = a + b
  b = a - b
  a = a - b


 
 
 
 

A3:

I see a problem there..
Var "a" can overflow, and the data will be corrupted.
This may be better:


  a = a - b
  b = a + b
  a = b - a