Wednesday 22 August 2012

How to swap two values without 3rd variable in PHP

How to swap values of two variables without using 3rd variable !


OK,

that's the most asked question when ever i went for an interview. Interviewer asks , can u swap values of two variables without taking 3rd variable ?

I mean, the simplest way to do this job is taking 3 variables

but the thing get tricky when we are asked to not to introduce 3rd variable at all. Here is the code to swap values between two variables without using/introducing 3rd variable, the most asked question in an interview for any kind of programming job !




This script is too small to get notice but it's quite complex and it tells a lot about programmer's logic and ability to solve complex problem.

Other important php job interview questions include

Top PHP interview Questions
  • Difference between require() , include() and include_once() functions
  • What is GET & POST, what is difference between the two
  • What are global functions in PHP?
  • Is php Object oriented?
  • Can we submit a form without a submit button
  • Why we use hidden variables in forms ?
  • How many ways are there to send a value from one page to another page.
  • Session and cookies, which is safest and why ?
  • What is php safe_mode()
  • What is sql injection and how to prevent it ?
  • How to get highest value in a column of database table.
  • How to get second highest values in a column.
  • How to define a constant in PHP
  • Name the top 5 php functions we used most !

No comments:

Post a Comment