GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Programming  >  C
Go To First  |  Previous Question  |  Next Question 
 C  |  Question 181 of 453    Print  

If the following program (myprog) is run from the command line as myprog friday tuesday sunday,
What would be the output?

main(int argc, char *argv[])
{
printf("%c",*++argv[1]);
}

A) r
B) f
C) m
D) y



  
Total Answers and Comments: 3 Last Update: July 30, 2009   
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
January 08, 2006 07:21:58   #1  
richa_yadav Member Since: January 2006   Contribution: 3    

RE: If the following program (myprog) is run from t...
A) r
 
Is this answer useful? Yes | No
July 30, 2009 00:47:57   #2  
abhimanipal Member Since: July 2009   Contribution: 22    

RE: If the following program (myprog) is run from the command line as myprog friday tuesday sunday, What would be the output? main(int argc, char *argv[]) { printf("%c",*++argv[1]); }
When we write argv[1] its the address of 1st character of the string pointed to by argv
When we increment argv the address is of the the second string ie friday
When we write *++argv[1] its prints the 1st alphabet of the string friday

 
Is this answer useful? Yes | No
July 30, 2009 00:50:35   #3  
abhimanipal Member Since: July 2009   Contribution: 22    

RE: If the following program (myprog) is run from the command line as myprog friday tuesday sunday, What would be the output? main(int argc, char *argv[]) { printf("%c",*++argv[1]); }
I am sorry argv[1] is the address of the 2 character of the string pointed to by argv...

So consequently the o/p is r and not f

 
Is this answer useful? Yes | No


 
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