GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Programming  >  C++
Go To First  |  Previous Question  |  Next Question 
 C++  |  Question 158 of 203    Print  
What does this function do:
What does this function do:

string f(const string &x) {
return x.empty()? x : f(x.substr(1)) + x[0];
}

What does this piece of code perform:

char *a=...., *b=....;
while(*b++ = *a++);




  
Total Answers and Comments: 5 Last Update: April 25, 2009     Asked by: Namataraginu 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: bapu_60
 
I think the first one is reversing the string and the second one is copying one string to other

Above answer was rated as good by the following members:
YaelG, Bhimasena
February 20, 2008 06:23:48   #1  
bapu_60 Member Since: February 2008   Contribution: 3    

RE: What does this function do:
I think the first one is reversing the string and the second one is copying one string to other
 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
March 22, 2008 20:34:26   #2  
rsuzoka Member Since: March 2008   Contribution: 1    

RE: What does this function do:
Yeah the first one reverses the string. I'm not too sure about the second one - it looks more like comparing two strings rather than copying one to another.

Any other comments????

 
Is this answer useful? Yes | No
March 24, 2008 04:14:58   #3  
bapu_60 Member Since: February 2008   Contribution: 3    

RE: What does this function do:
No if you see it is a single " " that is copying and it terminates when *a *b ' '
 
Is this answer useful? Yes | No
February 17, 2009 05:59:01   #4  
santhosh.kanchanapally Member Since: April 2008   Contribution: 10    

RE: What does this function do:
char *a "hai" *b "san";
while(*b++ *a++);


This program leads to crash as we are assigning one memory location to other memory location.

 
Is this answer useful? Yes | No
April 25, 2009 14:04:37   #5  
shantanu_hbd Member Since: April 2009   Contribution: 3    

RE: What does this function do:
Second function is copying 'a' to 'b' provided that 'a' should be a null terminated string.
 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape