Interview Questions  

Go Back   Interview Questions > Interview Questions & Answers > Information Technology > Programming Languages > C

C C Interview Questions, Learn by sharing C Interview Questions asked in various companies, Get Career advices, Interview Procedures from C experts, Post asked C Interview Questions and Answers.

   

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-02-2008, 11:44 AM
Senior Member
 
Join Date: Feb 2008
Posts: 9,095
Default How can we swap two

How can we swap two values without using a temporary?

Reply With Quote
  #2 (permalink)  
Old 04-27-2008, 02:34 PM
Junior Member
 
Join Date: Apr 2008
Posts: 4
Default

a=a-b;
b=b-a;
a=a-b;
Reply With Quote
  #3 (permalink)  
Old 04-28-2008, 07:42 AM
Junior Member
 
Join Date: Apr 2008
Posts: 3
Default Swapping

a=a*b;
b=a/b;
a=a/b;
Reply With Quote
  #4 (permalink)  
Old 04-28-2008, 07:44 AM
Junior Member
 
Join Date: Apr 2008
Posts: 3
Default swapping

Quote:
Originally Posted by rakgenius View Post
a=a-b;
b=b-a;
a=a-b;
sorry dude, this doesnt work, it shud be
a=a+b;
b=a-b;
a=a-b;
Reply With Quote
  #5 (permalink)  
Old 05-29-2008, 09:35 AM
Junior Member
 
Join Date: May 2008
Posts: 3
Default

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

// ^ - XOR
Reply With Quote
  #6 (permalink)  
Old 08-14-2008, 11:19 AM
Junior Member
 
Join Date: Aug 2008
Posts: 11
Default

int a=10,b=20;

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



printf("%d %d",a,b);
this code will work fine whether a >b or a
Reply With Quote
Reply

Tags
c language, interview questions

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On