The exec functions are variable: they take a variable number of parameters, so you can pass a variable number of arguments to the command. Functions should use NULL as a marker to mark the end of the argument list.
Inside the variational functions there is a loop that will iterate over a variable number of arguments. These loops need a final condition. In some cases, such as printf , the actual number of arguments may be inferred from another argument. In other functions, NULL used to indicate the end of a list.
Another option would be to add an additional function parameter for the number of arguments, but this would make the code a little more fragile, requiring the programmer to control the additional parameter, and not just always use NULL as the final argument.
You will also see (char *) 0 used as a marker:
execl("/bin/ls", "ls", "-l", (char *) 0);
source share