当前位置:网站首页>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 !!!
边栏推荐
- 【HCIE论述】RR-A
- Day 3 of jsbom and DOM learning
- PMP training organization
- leaflet如何优雅的展示重叠点位的气泡窗口
- 2022-06-13日报: 图灵奖得主:想要在学术生涯中获得成功,需要注意哪些问题?
- SAP UI5 如何通过 manifest.json 文件定义第三方库依赖关系
- M_8:设计消息队列存储消息数据的 MySQL 表格
- Real time preview of PHP in browser by vscade
- How to pass the PMP review?
- [leetcode] understanding and usage of map[key]+
猜你喜欢
Running of NCF dapr application instance
中科大USTC:Minrui Wang | 基于Transformer的多智能体强化学习的配电网稳压
NCF 的Dapr应用实例的运行
Matlab [path planning] - UAV drug distribution route optimization
Leetcode 2200. Find all k nearest neighbor subscripts in the array (yes, one pass)
2022年危險化學品經營單比特安全管理人員考試試題及在線模擬考試
vs studio_ How to use scanf in 2022
How to make maputnik, a vector tile matching artifact, support GeoServer
[matlab] two dimensional curve
如何实现OSM地图本地发布并自定义配图
随机推荐
[matlab] basic operation
Video tracker error troubleshooting
How to gracefully solve the offset problem of Baidu and Gaode maps in leaflet
VHDL programming experiment exercises collection
Explanation and practice of implicit transformation and implicit parameters in Scala
[matlab] matrix transformation and matrix evaluation
如何让矢量瓦片配图神器maputnik支持 geoserver
C # graphic tutorial (Fourth Edition) chapter7-7.6.1 virtual and override
Vscode实现PHP在浏览器实时预览
如何利用华为云容灾解决方案替代灾备一体机
How to use Huawei cloud disaster tolerance solution to replace disaster recovery all-in-one machine
[hcie discussion] multicast igmp-a
【Matlab】多项式计算
PMP training organization
设计消息队列存储信息数据的MySQL表结构
Start of u-boot_ Armboot analysis (I)
Running of NCF dapr application instance
Start of u-boot S analysis (III)
2022年危險化學品經營單比特安全管理人員考試試題及在線模擬考試
dict和set的基本操作