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"

Showing Answers 1 - 10 of 10 Answers

vanavill

  • Mar 7th, 2008
 


   initially J=0,then, it incremented by the arg value one. now it is 1.then it incremented 
by the arg value 2. now the value of J is 3. then it's value incremented by the arg value 3. now it's value is 6.now,the loop condition over. The J=6.
         
        so the answer is  6.

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