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.
Nani said:
10 years ago
I think in command line not allow the integer values. So it shows error.
Sealon said:
8 years ago
The argc is the number of paramters which is 4 (myprog, 10, 20,30), argv can be understood as *argv[4], regardless of the diffrence between pointer and array name.
Rit said:
8 years ago
If those are strings in loop what is the value of argc and how many times it will go?
Ruku said:
7 years ago
Here the argc is 4.
So according to this;
for(i=0; i<argc; i++)
=>myprog 10 20 30 be the answer.
So according to this;
for(i=0; i<argc; i++)
=>myprog 10 20 30 be the answer.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers