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

If the program (myprog) is run from the command line as myprog 1 2 3 , What would be the output?

main(int argc, char *argv[])
{
   int i;
   for(i=0;i<argc;i++)
   printf("%s",argv[i]);
}

A) 1 2 3
B) C:MYPROG.EXE123
C) MYP
D) None of the above



  
Total Answers and Comments: 5 Last Update: October 21, 2009   
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
March 21, 2006 09:22:09   #1  
mukul sharma        

RE: If the program (myprog) is run from the command...
right answer is B:because argv is char string which store command line as input and argc is int counter which give the length of this string.
 
Is this answer useful? Yes | No
November 03, 2007 18:17:24   #2  
Helen45 Member Since: November 2007   Contribution: 1    

RE: If the program (myprog) is run from the command...
what if I run my command from a disk different from C?
 
Is this answer useful? Yes | No
February 05, 2008 16:49:31   #3  
yrenster Member Since: February 2008   Contribution: 2    

RE: If the program (myprog) is run from the command line as myprog 1 2 3 , What would be the output? main(int argc, char *argv[]) {    int i;    for(i=0;i<argc;i++)    printf("%s",argv[i]); }
None of the above. It should be : myprog123. Because argv[0] "myprog" argv[1] "1" argv[2] "2" argv[3] "3".

 
Is this answer useful? Yes | No
February 06, 2008 07:19:25   #4  
prabhjots Member Since: February 2008   Contribution: 5    

RE: If the program (myprog) is run from the command line as myprog 1 2 3 , What would be the output? main(int argc, char *argv[]) {    int i;    for(i=0;i<argc;i++)    printf("%s",argv[i]); }
the result will be

c:mypgm.exe123

becoz argv[0] will be the location of ur program(be it c: or d:)

 
Is this answer useful? Yes | No
October 21, 2009 13:01:26   #5  
sunilkanna Member Since: October 2009   Contribution: 1    

RE: If the program (myprog) is run from the command line as myprog 1 2 3 , What would be the output? main(int argc, char *argv[]) {    int i;    for(i=0;i<argc;i++)    printf("%s",argv[i]); }
The answer is b. because command line argument includes file path as first argument.
 
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