C Programming - Command Line Arguments - Discussion
Discussion Forum : Command Line Arguments - Find Output of Program (Q.No. 12)
12.
What will be the output of the program (sample.c) given below if it is executed from the command line?
cmd> sample Jan Feb Mar
cmd> sample Jan Feb Mar
/* sample.c */
#include<stdio.h>
#include<dos.h>
int main(int arc, char *arv[])
{
int i;
for(i=1; i<_argc; i++)
printf("%s ", _argv[i]);
return 0;
}
Discussion:
17 comments Page 2 of 2.
Nitesh said:
1 decade ago
When it goes in the for loop then 3 is not greater than 3. So how does it prints March because their is no < = sign.
Dishank said:
9 years ago
@Kiran.
argc[1] is jan only then how can it print feb and march as feb is argc[2] while march is argc[3].
argc[1] is jan only then how can it print feb and march as feb is argc[2] while march is argc[3].
Rahul said:
8 years ago
Is ''arc'' and ''_argc'' same?
Matrika said:
8 years ago
@Parvathy.
As there are 4 arguments sample, Jan, Feb, March. So argc would be equal to 4. And the printing is done from the index 1 that means it will print the value of argv[1] as Jan, argv[2] as Feb and argv[3] as March. It will mot print sample as sample is present in argv[0].
As there are 4 arguments sample, Jan, Feb, March. So argc would be equal to 4. And the printing is done from the index 1 that means it will print the value of argv[1] as Jan, argv[2] as Feb and argv[3] as March. It will mot print sample as sample is present in argv[0].
Fatema Saba said:
6 years ago
@Rahul
Even I have the same doubt.
Is _argc and arc are the same and is _argv and arv is the same? Please, anyone, explain it.
Even I have the same doubt.
Is _argc and arc are the same and is _argv and arv is the same? Please, anyone, explain it.
Shubh said:
5 years ago
Can someone explain it clearly?
Opkuma said:
4 years ago
I didn't get it, please explain.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers