字符串数组

  • char **a
    • a是一个指针,指向另一个指针,那个指针指向一个字符(串)
  • char a[][n]
    • 一个数组a,每个单元都能放下长度为10的字符(串)
    • 缺点,字符串长度固定,不能超出
  • char *a[]
    • 一个数组a,每个单元都是一个char*,可以存放字符串
    • 相比a[][],字符串的长度不受限制

程序参数

  • int main(int argc,char const *argv[])
  • argc是argv字符串数组的数量
  • argv[0] 是启动程序的命令本身
    • 当使用符号链接时,反应符号链接的名字
  • 当然可以不叫argc和argv,名字可以自己取
#include<stdio.h>

int main(int n,char const *a[]){
    for(int i = 0; i < n; i++){
        printf("%d => %s\n",i,a[i]);
    }
    return 0;
}

将该文件编译为叫做test的程序,使用 ./test 运行

0 => ./test

使用 ./test abc def 114 514 运行

0 => ./test
1 => abc
2 => def
3 => 114
4 => 514

使用 ln -s test test2 创建符号链接

使用 ./test2 abc def 114 514 运行

0 => ./test2
1 => abc
2 => def
3 => 114
4 => 514
最后修改:2023 年 04 月 28 日
如果觉得我的文章对你有用,请随意赞赏