main function overview
The main function is defined in a C shared object (CSO). The definition of the main function
returns an int data type and takes either no parameters or two
parameters.
The following example shows the definition of a main function that returns
an
int and does not take any parameters:
int main(void) { /* code for main */ }The following example shows the definition of a main function that returns
an
int and takes two parameters.
int main(int argc, char **argv) { /* code for main */ }Where:
- The
intdata type is set to the number of argument strings passed to the main function. - The
char**data type is set to the vector of pointers to argument strings passed to main function.
The argc and argv parameter names are established
by the C/C++ programming conventions.
The variables that are used with these parameters have the following restrictions:
argc>= 0argv[argc]is a null pointerargv[0]throughargv[argc-1]point to NUL ('\0') and ends argument stringsargv[0]contains the shared object name ifargc>= 0.