Commandline Arguments

main() Can Take Parameters

So far: int main(void)

  • A process has an exit status ⟶ implicitly int main(...)

  • ⟶ compiler magic: main() is special

  • C++: compiler error if main() does not return an int

  • No commandline arguments expected ⟶ main(void)

⟶ How are commandline arguments passed?

Commandline Arguments

int main(int argc, char **argv)
{
    char *opt = argv[1]; /* "-l" */
    char *dir = argv[2]; /* "/tmp" */
    ...
}

ls -l /tmp

../../../../../../_images/05-10-00-argv-main.svg