C Programming - Command Line Arguments - Discussion
Discussion Forum : Command Line Arguments - Find Output of Program (Q.No. 1)
1.
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>
int main(int argc, char **argv)
{
printf("%c\n", **++argv);
return 0;
}
Discussion:
26 comments Page 3 of 3.
Satya said:
1 decade ago
Senu answer is good.
KHAGESH GUPTA said:
1 decade ago
Real thing is here
*argv=pointer to "myprog"(=base address) and equivalent to argv[0]
then preincrements
*++argv=pointer to "one"(more specifically pointer to "o") equivalent to argv[1]
**++argv=value at this address
thus ans is o
*argv=pointer to "myprog"(=base address) and equivalent to argv[0]
then preincrements
*++argv=pointer to "one"(more specifically pointer to "o") equivalent to argv[1]
**++argv=value at this address
thus ans is o
Murthy said:
1 decade ago
Please give me brief description.
Navneet agarwal said:
1 decade ago
Seenu answer is good and understood.
Anand Shankar Jha said:
1 decade ago
I think seenu's logic is good enough to answer the question.
Good seenu.
since ++ is prefix with argv hence pre increament happens in argument and the the array is char type, so, it stores one char at a time.
So, Answer must be C i.e. "o".
Good seenu.
since ++ is prefix with argv hence pre increament happens in argument and the the array is char type, so, it stores one char at a time.
So, Answer must be C i.e. "o".
Seenu said:
2 decades ago
argv[0] = myprog
argv[1] = one
So **++argv=> argv[1].
And %c is output so first char of one ==> o.
argv[1] = one
So **++argv=> argv[1].
And %c is output so first char of one ==> o.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers