C Programming - Command Line Arguments - Discussion
Discussion Forum : Command Line Arguments - Find Output of Program (Q.No. 2)
2.
What will be the output of the program (myprog.c) given below if it is executed from the command line?
cmd> myprog one two three
cmd> myprog one two three
/* myprog.c */
#include<stdio.h>
#include<stdlib.h>
int main(int argc, char **argv)
{
printf("%s\n", *++argv);
return 0;
}
Discussion:
15 comments Page 2 of 2.
Priya said:
1 decade ago
Why is the argc mentioned here unnecessarily?
Klobin said:
1 decade ago
argc is 4 here as ---- myprogs is also considered as no.1.
So the total becomes four ---- argument counter will get value:4.
So the total becomes four ---- argument counter will get value:4.
Ganesh sable jtc said:
1 decade ago
Rule of pointer *p++ is increment address.
Suppose int *p++ address is 2000 then increment 2004 because pointer size 4.
And *++p is increment actual value suppose 456 in array so display 5.
Suppose int *p++ address is 2000 then increment 2004 because pointer size 4.
And *++p is increment actual value suppose 456 in array so display 5.
Abhinav Kumar said:
9 years ago
**++argv should be used instead of *++argv.
Anshu said:
7 years ago
Good explanation, Thanks @Sholvi.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers