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

This question is related to Sonata Interview

Showing Answers 1 - 4 of 4 Answers


  • Oct 25th, 2005

a) r

  Was this answer useful?  Yes


  • Feb 12th, 2007

argv[1] refers to first comand line parameter here it is myprog . *++ refers to y

  Was this answer useful?  Yes

Amber Bhardwaj

  • Apr 15th, 2014

For example, the command line

gcc -o myprog myprog.c
would result in the following values internal to GCC:

  1. argc

  2. 4

  3. argv[0]

  4. gcc

  5. argv[1]

  6. -o

  7. argv[2]

  8. myprog

  9. argv[3]

  10. 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.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.


Related Answered Questions


Related Open Questions