C Programming - Command Line Arguments - Discussion
Discussion Forum : Command Line Arguments - Find Output of Program (Q.No. 7)
7.
What will be the output of the program if it is executed like below?
cmd> sample
cmd> sample
/* sample.c */
#include<stdio.h>
int main(int argc, char **argv)
{
printf("%s\n", argv[argc-1]);
return 0;
}
Discussion:
15 comments Page 1 of 2.
Shivathmika said:
5 years ago
Here the sample is stored in argv[0] and the argc is 1 and the line argv[argc-1] gives us argv[0]
Because the value of argc is 1.
So the output is sample.
Because the value of argc is 1.
So the output is sample.
(1)
Akash said:
8 years ago
Thank you so much @Pallavi.
Saptaparni said:
8 years ago
@Jamuna.
Because argc is the number of elements. Here there is only one element that is Sample. So argc is 1.
Because argc is the number of elements. Here there is only one element that is Sample. So argc is 1.
JAMUNA said:
8 years ago
How we consider argc is equal to 1? Explain.
Ravikanth said:
9 years ago
Why argv[] taken as a double pointer, can anyone explain?
Yogesh said:
9 years ago
How argc is 1 here? Please explain it.
Amit said:
1 decade ago
@ Sneha.
*argv is just a pointer which points to any location.
**argv points out the element stored in that location (called as dereferencing of pointers).
*argv is just a pointer which points to any location.
**argv points out the element stored in that location (called as dereferencing of pointers).
Sneha said:
1 decade ago
Can anyone please explain me what is the difference between *argv and **argv?
Sandeep Negi said:
1 decade ago
Output is C:\TC\BIN\SAMPLE.EXE when using argv with %s.
But when printing it using %c it does not show path of file but the filename like SAMPLE.EXE
But when printing it using %c it does not show path of file but the filename like SAMPLE.EXE
Reegan Kothari said:
1 decade ago
thanks pallavi.....
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers