Commandline Arguments¶
main()
Can Take Parameters¶
So far: int main(void)
A process has an exit status ⟶ implicitly
int main(...)
⟶ compiler magic:
main()
is specialC++: compiler error if
main()
does not return anint
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