In this commands why argc value is 2 not 4 ?

In command line argument example when we run program, it count all cmd argument but in case argc is 2 ? why not 4 ?

1 Answer 1


Because the arguments passed to your program are only 2:

  • the name of your program (./arg-0)
  • the argument you pass to it (pri).

The > file.txt part of the command is used by the command line to redirect the standard output of your program, and is not passed as an argument in your program.

  • I gotta learn to type faster. ;-) Chris is exactly right. The redirect arrow and the filename that follows are not considered part of the command that invokes arg-0, so they will not be counted. Instead, they are operating system directives.
    – Cliff B
    Commented Jul 22, 2016 at 7:14
  • Ha! I wish I typed as fast as you. It has been a long time since I last contributed and I missed you all guys, so I thought to come back and try to offer a little help! :P
    – ChrisG
    Commented Jul 22, 2016 at 7:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .