If the following 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,j=0; for(i=0;i<argc;i++) j=j+ atoi(argv[i]); printf("%d",j); } a) 1 2 3 b) 6 c) error d) "123"

This question is related to Sonata Interview

Showing Answers 1 - 8 of 8 Answers

Tonni

  • Apr 7th, 2007
 

b) 6

atoi fails on the first element of argv[], being "command.exe", but atoi returns 0 in case of failure.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions