C Programming - Command Line Arguments - Discussion
Discussion Forum : Command Line Arguments - Find Output of Program (Q.No. 20)
20.
What will be the output of the program (myprog.c) given below if it is executed from the command line?
cmd> myprog 10 20 30
cmd> myprog 10 20 30
/* myprog.c */
#include<stdio.h>
int main(int argc, char **argv)
{
int i;
for(i=0; i<argc; i++)
printf("%s\n", argv[i]);
return 0;
}
Discussion:
14 comments Page 2 of 2.
Sudheer said:
1 decade ago
I thought, first argument is filename and later are normal arguments. So it prints filename first and later remaining arguments will be printed.
Vijeta said:
1 decade ago
Hey Rabi can you explain it in detail, I haven't understood.
Rabi said:
1 decade ago
The actual declaration of main command line is myprog "10" "20" "30" where each members of command line are string constant. Hence "10", "20", "30" are string constant not integer value. Hence there is no doubt of int value.
Devesh agarwal said:
1 decade ago
Does any have the explanation for this ?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers