You don't have to type "stdout\0" on the command line. Whichever way your system makes command-line arguments available to your process (it differs by operating system) automatically adds the null character.
As you know, a C-style string is terminated by the null character, which is written in code as '\0'. If that character weren't at the end of the string, a function such as strcmp
would keep going well beyond the end of the string, since such a string flouts convention. Since the terminating null character is the C convention, however, the compiler is smart enough to add the null character to the end of a string literal, and the system is smart enough to add the null character to the command-line arguments stored in the memory of a freshly created process. If argc
is greater than 3, and the third argument you type on the command-line for your program is "stdout", the call to strcmp(argv[3], "stdout")
will return 0 to mean that the two strings match.