Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the use of main () function in C language?

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

C language main () function what is useful, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.

In C language, the main function is the entrance to the program. It can be written in four ways, namely:

The first three without parameters are more common ways of writing. What is the meaning of the two parameters in the fourth way? Let's give a brief introduction. First of all, the main function cannot be called by other functions, so the actual values of the formal parameters argc and argv cannot be passed in from other functions, so where should the parameters be passed in? Is obtained from the operating system command line. So these two parameters are also called command-line arguments, where argc is the number of command-line arguments and argv is the first address of the string command-line arguments. Let's look at an example:

Type the key combination [win+r] to open the run window, type "cmd" and enter to enter the command line environment:

Enter the "gcc hello.c-o hello.exe" command to compile, and then enter "hello.exe cmd1 cmd2 cmd3 cmd4 cmd5" (the general form of the command line at the DOS prompt is: C:\ > executable file name parameter parameter. ) pass parameters to the main function, and the output is as follows:

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report