当前位置:网站首页>关于c语言main函数中int argc,char **argv的理解
关于c语言main函数中int argc,char **argv的理解
2022-06-30 01:16:00 【yscisco】
关于c语言main函数中int argc,char **argv的理解
c语言main函数通常形如int main(int argc, char **argv),那么argc和argv代表啥呢?
其实,argc表示传入main函数的参数的个数;而argv表示传入main函数的参数的列表。当然,此处的argc和argv是可以换成别的名字的,因为argc (argument count)和argv(argument vector)用的比较多,所以建议自己写的代码也用这俩名字。另外,char ** 表示纸箱字符型指针的指针。测试代码如下
#include <stdio.h>
int main(int argc, char **argv)
{
int i=0;
printf("%d\n",argc);
for (i=0;i<argc;i++)
{
printf("%s\n",argv[i]);
}
}
[[email protected] c]# ./a.out arg1 arg2 arg3
4
./a.out
arg1
arg2
arg3
更改名称后的代码
#include <stdio.h>
int main(int count, char **vector)
{
int i=0;
printf("%d\n",count);
for (i=0;i<count;i++)
{
printf("%s\n",vector[i]);
}
}
[[email protected] c]# ./new one two three four
5
./new
one
two
three
four
边栏推荐
- I learned database at station B (V): DQL exercise
- Preliminary understanding of NVIDIA Jetson nano
- 81. 搜索旋转排序数组 II
- 快手伸手“供给侧”,找到直播电商的“源头活水”?
- Seata and the three platforms are working together in the summer of programming. Millions of bonuses are waiting for you
- Mechanical --nx2007 (UG) -- gap analysis (interference inspection)
- How does webapi relate to the database of MS SQL?
- How to view the size of all files in a folder?
- [deep learning compilation] operator compilation IR conversion
- Simple pages
猜你喜欢

How to unify the use of package manager in a project?

Clean, talk, bring children, and get rid of the label of "artificial mental retardation" for the sweeper

Transaction summary on June 25, 2022

浅析现代Web端im即时通讯开发技术

What if you can't write your composition well? Ape counseling: parents should pay attention to these points

【论文写作】英文论文写作指南

如何拒绝期末复习无用功?猿辅导:找准适合自己的复习方法很重要

赛芯电子冲刺科创板上市:拟募资6.23亿元,共有64项专利申请信息

How to build your own blog website by yourself

How to customize templates and quickly generate complete code in idea?
随机推荐
Analysis of natural frequency and buckling load of cylinder by finite element method
81. 搜索旋转排序数组 II
Netease cloud music beta music social app "mus" matches friends of the same frequency through music
If the amount exceeds 6 digits after the decimal point, only 6 digits will be reserved, and if it is less than 6 digits, it will remain the same - Basic accumulation
Sentinel source code analysis Part 6 - sentinel adapter module Chapter 4 zuul2 gateway
Transaction summary on June 25, 2022
postman 之接口关联
Seata 与三大平台携手编程之夏,百万奖金等你来拿
Nested call and chained access of functions in handwritten C language
Newton method (optimization of two variable functions)
【论文写作】英文论文写作指南
c语言选择,循环概述
【Games101】Transformation
Comparison between strings localecompare
The first unlucky person watching eth 2.0
81. search rotation sort array II
xshell中怎么切换到root用户
Online text digit recognition list summation tool
[deep learning compilation] operator compilation IR conversion
C language selection, loop overview