通过以下例子来作说明:
[root@localhost arg]# cat argtest.c
#include <stdio.h>//#包含<stdio.h>
/* 整数类型主函数(整数类型统计参数个数,字符类型*数组指针至字符[]) */
int main(int argc,char* argv[])
{
printf("%d\n",argc);//格式化输出
while(argc)//当(统计参数个数)
printf("%s\n",argv[--argc]);//格式化输出
return 0;//返回0;正常退出
}
[root@localhost arg]# gcc argtest.c
[root@localhost arg]# ./a.out a b
3
b
a
./a.out
[root@localhost arg]#
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有