Search code examples
cargvargc

Why does main(int argc, char* argv[]) take two argument?


I always thought that argc was required to mark the end of argv but I just learned that argv[argc] == NULL by definition. Am I right in thinking that argc is totally redundant? If so, I always thought C made away with redundancy in the name of efficiency. Is my assumption wrong or there's a historic reason behind this? If the reason is historic, can you elaborate?


Solution

  • History.

    Harbison & Steel (5th Edition, 9.9 "The main program") says the following:

    Standard C requires that argv[argc] be a null pointer, but it is not so in some older implementations.