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.
Swapnil said:
9 years ago
Thanks @Cherry.
Priyanka said:
9 years ago
Consider a pointer *p for storing single dimension array. *++p points to next element in the array.
In the case of 2-dimensional array **p is used and **++p points to next word.
Finally coming to answer **argv[] is a 2-dimensional representation of command line arguments and,
**++argv[] points to next word. %c is used for printing character at that position. So, the answer is "o".
In the case of 2-dimensional array **p is used and **++p points to next word.
Finally coming to answer **argv[] is a 2-dimensional representation of command line arguments and,
**++argv[] points to next word. %c is used for printing character at that position. So, the answer is "o".
GORIPARTHI. Udaya lakshmi said:
8 years ago
How the answer comes o?
Nikhil n said:
8 years ago
Perfect answer @Seenu.
Sanjana said:
7 years ago
But argv[0] must be a program name right?
Sravya said:
7 years ago
Good explanation @Cherry.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers