ALLInterview.com :: Home Page            
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
Google
   
 
Categories >> Code Snippets >> Programming Code >> C Code
 
 


 

 
 C Code interview questions  C Code Interview Questions (401)
 C++ Code interview questions  C++ Code Interview Questions (121)
 VC++ Code interview questions  VC++ Code Interview Questions (2)
 Java Code interview questions  Java Code Interview Questions (57)
 Dot Net Code interview questions  Dot Net Code Interview Questions (113)
 Visual Basic Code interview questions  Visual Basic Code Interview Questions (8)
 Programming Code AllOther interview questions  Programming Code AllOther Interview Questions (37)
Question
How to swap two variables, without using third variable ?
 Question Submitted By :: Swapna
I also faced this Question!!     Rank Answer Posted By  
 
  Re: How to swap two variables, without using third variable ?
Answer
# 1
Hi this question was asked in my interview.
Ans is :

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

Any other solution?
 
Is This Answer Correct ?    1711 Yes 216 No
Swapna
 
  Re: How to swap two variables, without using third variable ?
Answer
# 2
use xor to swap

a = a^b
b= a^b
a= a^b
 
Is This Answer Correct ?    528 Yes 161 No
Guest
 
 
 
  Re: How to swap two variables, without using third variable ?
Answer
# 3
Ans is :

a=a*b;
b=a/b;
a=a/b;
 
Is This Answer Correct ?    523 Yes 176 No
Somasekhar
 
  Re: How to swap two variables, without using third variable ?
Answer
# 4
a=5,b=10
a=a-b;
b=a+b;
a=a+b;
 
Is This Answer Correct ?    182 Yes 387 No
Vinay_csjm
 
  Re: How to swap two variables, without using third variable ?
Answer
# 5
Only #2 will work. The others may over/under flow. 
Is This Answer Correct ?    81 Yes 129 No
Er
 
  Re: How to swap two variables, without using third variable ?
Answer
# 6
a=a+b;
b=a-b;
a=a-b
 
Is This Answer Correct ?    291 Yes 56 No
Kiran
 
  Re: How to swap two variables, without using third variable ?
Answer
# 7
b=a-b;
a=a-b;
b=a+b;
 
Is This Answer Correct ?    98 Yes 83 No
P.muthukumar
 
  Re: How to swap two variables, without using third variable ?
Answer
# 8
2 one will work correct 
Is This Answer Correct ?    78 Yes 44 No
Gowtham
 
  Re: How to swap two variables, without using third variable ?
Answer
# 9
plz check 3 aswer is perfect, 2 one mat be wrong in some cases 
Is This Answer Correct ?    47 Yes 61 No
Koneru Gowtham
 
  Re: How to swap two variables, without using third variable ?
Answer
# 10
a=b-a+(b=a); 
Is This Answer Correct ?    113 Yes 74 No
Partha
 

 
 
 
Other C Code Interview Questions
 
  Question Asked @ Answers
 
#define DIM( array, type) sizeof(array)/sizeof(type) main() { int arr[10]; printf(The dimension of the array is %d, DIM(arr, int)); }   1
‎#define good bad main() { int good=1; int bad=0; printf ("good is:%d",good); }   2
main() { char p[ ]="%d\n"; p[1] = 'c'; printf(p,65); }   2
What is "far" and "near" pointers in "c"...?   3
How to swap two variables, without using third variable ? HCL 104
abcdedcba abc cba ab ba a a   2
void main () { int x = 10; printf ("x = %d, y = %d", x,--x++); } a. 10, 10 b. 10, 9 c. 10, 11 d. none of the above HCL 2
how can u draw a rectangle in C Wipro 53
main(){ char a[100]; a[0]='a';a[1]]='b';a[2]='c';a[4]='d'; abc(a); } abc(char a[]){ a++; printf("%c",*a); a++; printf("%c",*a); }   2
void main() { int i=10, j=2; int *ip= &i, *jp = &j; int k = *ip/*jp; printf(%d,k); }   1
Question: We would like to design and implement a programming solution to the reader-writer problem using semaphores in C language under UNIX. We assume that we have three readers and two writers processes that would run concurrently. A writer is to update (write) into one memory location (lets say a variable of type integer named temp initialized to 0). In the other hand, a reader is to read the content of temp and display its content on the screen in a formatted output. One writer can access the shared data exclusively without the presence of other writer or any reader, whereas, a reader may access the shared memory for reading with the presence of other readers (but not writers).   1
struct aaa{ struct aaa *prev; int i; struct aaa *next; }; main() { struct aaa abc,def,ghi,jkl; int x=100; abc.i=0;abc.prev=&jkl; abc.next=&def; def.i=1;def.prev=&abc;def.next=&ghi; ghi.i=2;ghi.prev=&def; ghi.next=&jkl; jkl.i=3;jkl.prev=&ghi;jkl.next=&abc; x=abc.next->next->prev->next->i; printf("%d",x); }   1
 
For more C Code Interview Questions Click Here 
 
 
 
 
 


   
Copyright Policy  |  Terms of Service  |  Articles  |  Site Map  |  RSS Site Map  |  Contact Us
   
Copyright 2013  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  KalAajKal.com