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
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;
}
Discussion:
15 comments Page 2 of 2.
Rran said:
10 years ago
Can kindly any one please explain how to execute in Dev CPP to dos please explain the process please?
Parth said:
9 years ago
Thank you for this explanation.
Devendar said:
8 years ago
I think the answer is wrong because there is no {} to for loop. The program will execute differently and the output will come as.
0136.
0136.
Kajol jain said:
8 years ago
@Rran.
Just save your file in dev cpp, then compile and run it. After that open command prompt, write your path where your file (program) has been saved. Then just write your program name give space and give inputs (value for the *argv[] argument) according to your code and then press enter. You'll see your output.
Just save your file in dev cpp, then compile and run it. After that open command prompt, write your path where your file (program) has been saved. Then just write your program name give space and give inputs (value for the *argv[] argument) according to your code and then press enter. You'll see your output.
Anonymus said:
6 years ago
Thanks for the clear explanation @Sundar.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers