Search code examples
cargvargc

how to tell when you've reached the end of a C array? (specifically argv)


been asked a question on this, basically coming up with argc...without actually having argc

if your given argv, which as I understand essentially a array of pointers to the relevant char arrays of each inputted argument,

how would I actually go about counting the number of pointers in argv?


Solution

  • The C standard specifies:

    argv[argc] shall be a null pointer.
    

    So you can always detect the end by testing for 0.