If the following program (myprog) is run from the command line as myprog friday tuesday sunday,
What would be the output?
main(int argc, char *argv[])
{
printf("%c",*++argv[1]);
}
a) r b) f c) m d) y
The answer is a) r as argv[1] is friday and argv[0] is myprog
Amber Bhardwaj
Apr 15th, 2014
For example, the command line
gcc -o myprog myprog.c
would result in the following values internal to GCC:
Code
argc
4
argv[0]
gcc
argv[1]
-o
argv[2]
myprog
argv[3]
myprog.c
As you can see, the first argument (argv[0]) is the name by which the program was called, in this case gcc. Thus, there will always be at least one argument to a program, and argc will always be at least 1.
If the following program (myprog) is run from the command line as myprog friday tuesday sunday, What would be the output? main(int argc, char *argv[]) { printf("%c",*++argv[1]); } a) r b) f c) m d) y
Related Answered Questions
Related Open Questions