C Programming - Command Line Arguments - Discussion
Discussion Forum : Command Line Arguments - Find Output of Program (Q.No. 6)
6.
What will be the output of the program (sample.c) given below if it is executed from the command line?
cmd> sample "*.c"
cmd> sample "*.c"
/* sample.c */
#include<stdio.h>
int main(int argc, int *argv)
{
int i;
for(i=1; i<argc; i++)
printf("%s\n", argv[i]);
return 0;
}
Discussion:
22 comments Page 2 of 3.
Prashant Kumar said:
8 years ago
I am getting the output as list of all .c file in the current directory? why it's so?
Kavithha said:
1 decade ago
Since argv[] is a string, it print ly the string pointed by the argv[1] i.e. *.c .
Shail said:
1 decade ago
Warning: format \'%s\' expects type \'char *\', but argument 2 has type \'int\'.
Mangusta said:
1 decade ago
Hey, But argument is char * argv, not char* *argv or char* argv[].
Anu said:
1 decade ago
Can someone explain about the output of the above program ?
AppiReddy said:
1 decade ago
Any one can explain the output of the above program please.
Anish said:
1 decade ago
argc=2
argv[0]=sample
argv[1]=*.c
So it prints *.c
argv[0]=sample
argv[1]=*.c
So it prints *.c
Varun Gupta said:
1 decade ago
@Chandrasekar not a relevant explanation
Tanya said:
7 years ago
Please explain the correct answer.
Shamshad said:
1 decade ago
Why don't the output be "*.c" ?.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers