Where can the main function be located in C language?

王林
Release: 2020-07-18 10:58:19
Original
12247 people have browsed it

The main function in C language can be at any position. Each C language program has one and only one main function (main()), and the program must start with the main() function, which is the first function called when the program starts. Function definition form: [int main(void){}].

Where can the main function be located in C language?

C language stipulates that in a C program, the main() function can be at any location.

(Recommended tutorial: c language tutorial)

Analysis:

Each C program has one and only one main function (main), and the program Execution must start from the main() function, and the main() function can be placed anywhere in the program.

Detailed introduction:

A C program compiled in the host environment must define a function named main, which is the first function called when the program starts.

The definition of main() function has the following two forms:

(1) The function has no parameters and the return value is int type.

int main( void ) { /* … */ }
Copy after login

(2) The function has two parameters, the types are int and char**, and the return value is of type int.

int main( int argc, char *argv[ ] ) { /* … */ }
Copy after login

Both definition methods are consistent with the C language standard. In addition, many C implementations also support the third, non-standard syntax definition:

int main( int argc, char *argv[ ], char *envp[ ] ) { /* … */ }
Copy after login

The function return value is int and has 3 parameters: the first is int, the other two It's char**.

The above is the detailed content of Where can the main function be located in C language?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!