How many ways to write the main function in C language?

Publisher:郑大大Latest update time:2023-06-21 Source: elecfans Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

I have been writing a function since I started learning C language, so do you know its standard writing method?


The main function, also known as the main function, is the starting point for program execution. What does the main function we usually write look like?


1. Is that so?

main(){}

2. Is this still the case?

void main(){}

3. Still like this?

int main(void){}

4. Still like this?

int main(){}

5. Still like this?

int main(int argc,char *argv[]){}

There are so many ways of writing above, so which one is the correct way of writing?

Check the C89/C99/C11 standard document, which clearly fixes two ways of writing:

int main(void) { /* 。。。。。。 */ }int main(int argc, char *argv[]) { /* 。。。。。。 */ }

Therefore, other writing methods do not meet the standards. Some are historical relics, some are compiler extensions, and some are unknown where they came from.

So having said all this, for the general portability of the code, it is recommended to use the form provided by the standard, or it is recommended to use the two writing methods specified in the standard document. If a function determines that no parameters need to be passed in, then using void qualification is a good choice.

So, do you understand how to write the main function?


Reference address:How many ways to write the main function in C language?

Previous article:How much do you know about the internal structure of a microcontroller?
Next article:Design of VIIC1.0 software package based on I2C bus application calling platform mode

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号