当前位置:网站首页>On the parameters of main function in C language
On the parameters of main function in C language
2022-06-12 23:56:00 【Guigui-23】
Preface : This is the first time that the author has written a technical article , The format may not be very beautiful , Please bear with me . The main environment used is Linux, Because the author is learning embedded .
1,main Function prototype and the meaning of parameters
Prototype :
For us beginners , People don't care much about it main The function prototype , Just know the function usage , So they are basically written as
int main() perhaps void main; However main The function also has two very important arguments ; Its function prototype is :
int main(int argc,char *argv[]);
significance :
among ,argc It's a int The variable of type represents under standard input ( Command line ), Number of parameters entered ;argv It's a char Pointer array of type , It stores standard input ( Command line ) Input parameter string .
2, Example
Compared with boring words , Example is the best proof
vi egmain.c //linux in vi Editor commands , It means to create a .c file , The file named egmain/*egmain The content of */
#include <stdio.h>
int main(int argc,char *argv[])
{
printf("argc The number of %d\n",argc);
printf("argv[0] For the %s\n",argv[0]);
printf("argv[1] For the %s\n",argv[1]);
printf("argv[2] For the %s\n",argv[2]);
return 0;
}result :
gcc egmain.c //gcc Compiler gcc The order of , It means to compile egmain, The executable file generated by default without parameters is named
a.out
./a.out hello world // To run an executable program 
From the results
Under standard input , Take the space as the separator ,main The function will also ./a.out As input , therefore argv[0] by ./a.out,hello For the first time
Two inputs ,world For the third input ;
ok, Here we are , I think I have understood well drilling main Function parameter usage ; If you think it's useful, you can like it , Comment in support of . thank !!!
边栏推荐
- Machining Industry MES system Mold Industry MES system CNCl Medium Industry MES System MES code scanning and reporting MES data collection
- Xi'an Jiaotong 22nd autumn e-commerce technology online expansion resources (IV) [standard answer]
- 2022-06-13日报: 图灵奖得主:想要在学术生涯中获得成功,需要注意哪些问题?
- 2022年G3锅炉水处理考题模拟考试平台操作
- Case sharing of online real queuing system reconfiguration -- practical part
- How to gracefully solve the offset problem of Baidu and Gaode maps in leaflet
- 基于Three.js海上风电数字孪生三维效果
- 2022年6月11日记:王老师的春天,混入
- leaflet如何加载10万条数据
- How to get Matplotlib figure size
猜你喜欢
![[matlab] 3D curve and 3D surface](/img/50/44fec1cae6e2bbab1d9e000578f281.png)
[matlab] 3D curve and 3D surface

H5时代leaflet中还在用DivIcon?

2022年危險化學品經營單比特安全管理人員考試試題及在線模擬考試

Running of NCF dapr application instance

vs studio_ How to use scanf in 2022

The PMP examination time in March 2022 is set -- "March 27"
![[matlab] two dimensional curve](/img/5a/bd69c78513fe4b59b2c63dc3679841.png)
[matlab] two dimensional curve

array

leaflet如何优雅的展示重叠点位的气泡窗口

What are the PMP scores?
随机推荐
VHDL programming experiment exercises collection
2022 questions d'examen pour le personnel de gestion de la sécurité de l'unit é de gestion des produits chimiques dangereux et examen de simulation en ligne
How about opening a securities account in flush? Is it safe or not
Accelerating with Dali modules
PLC也能制作小游戏----Codesys编写猜数字小游戏
H5時代leaflet中還在用DivIcon?
leaflet中如何优雅的解决百度、高德地图的偏移问题
Examination questions and online simulation examination for safety management personnel of hazardous chemical business units in 2022
Will PM (Project Manager) take the PMP Exam?
PMP renewal | PDU specific operation diagram
M_8:设计消息队列存储消息数据的 MySQL 表格
Huawei cloud elastic ECS use [Huawei cloud to jianzhiyuan]
PMP test difficulty and pass rate
如何实现OSM地图本地发布并自定义配图
线上真实排队系统重构案例分享——实战篇
Enterprise wechat H5_ Authentication, H5 application web page authorization login to obtain identity
【HCIE论述】RR-A
[matlab] matrix transformation and matrix evaluation
2022年6月11日记:王老师的春天,混入
2022年危险化学品经营单位安全管理人员考试试题及在线模拟考试