I have to give some arguments while executing in the terminal,
No, you don't have to. You may give some arguments. There are conventions regarding program arguments (but these are just conventions, not requirements).
It is perfectly possible to write some C code with a main
without argument, or with ignored arguments. Then you'll compile your program into some executable myprog
and you just type ./myprog
(or even just myprog
if your PATH
variable mentions at the right place the directory containing your myprog
) in your terminal.
The C11 standard n1570 specifies in §5.1.2.2.1 [Program startup] that
The function called at program startup is named main
. The implementation declares no
prototype for this function. It shall be defined with a return type of int and with no
parameters:
int main(void) { /* ... */ }
or with two parameters (referred to here as argc and argv, though any names may be
used, as they are local to the function in which they are declared):
int main(int argc, char *argv[]) { /* ... */ }
or equivalent) or in some other implementation-defined manner.
The POSIX standard specifies further the relation between the command line, the execve function, and the main
of your program. See also this.
In practice I strongly recommend, in any serious program running on a POSIX system, to give two argc
& argv
arguments to main
and to parse them following established conventions (In particular, I hate serious programs not understanding --help
and --version
).