C Programming - Command Line Arguments - Discussion

Discussion Forum : Command Line Arguments - Find Output of Program (Q.No. 17)
17.
What will be the output of the program (myprog.c) given below if it is executed from the command line?
cmd> myprog 1 2 3
/* myprog.c */
#include<stdio.h>
#include<stdlib.h>

int main(int argc, char **argv)
{
    int i, j=0;
    for(i=0; i<argc; i++)
        j = j+atoi(argv[i]);
    printf("%d\n", j);
    return 0;
}
123
6
Error
"123"
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
15 comments Page 2 of 2.

Sreenivas said:   1 decade ago
Sunder your explanation was awesome.

Sandiya said:   1 decade ago
Thank you Sundar. Nice explanation.

Parth said:   9 years ago
Thank you for this explanation.

Marichamy said:   1 decade ago
Good explanation Sundar.

Rajesh said:   1 decade ago
Nice explanation sundar.


Post your comments here:

Your comments will be displayed after verification.