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.
Prajesh Bhushan said:
2 decades ago
Can't understand. Please help me understand the logic behind it.
PallavidBest said:
2 decades ago
The argv is a double pointer to character array string which is taken as input on command line. argc is total number of argument taken on command line. Here argc=1. So argv[argc-1]=argv[0], argv[0] will refer to sample. So the output.
(1)
Raksha said:
1 decade ago
thanks pallav.........
Handyrockzz said:
1 decade ago
tanks pallvi
Gandhi said:
1 decade ago
thanks himadri
Reegan Kothari said:
1 decade ago
thanks pallavi.....
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
Sneha said:
1 decade ago
Can anyone please explain me what is the difference between *argv and **argv?
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).
Yogesh said:
9 years ago
How argc is 1 here? Please explain it.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers