zoukankan      html  css  js  c++  java
  • linux c 的main 函数中的return 和 查看返回参数 argv 与 argc 作用

    hello.c

    #include <stdio.h>
    
    int main(int argv, char* argc[])
    {
        printf("hello word!
    ");
        return 0;
    }

    编译后  直接运行   && 作用为连接命令

    gcc hello.c -o main.out && ./main.out

    再运行  就查看返回参数

    echo $?  

    argv作用:

    main.c文件代码

    #include <stdio.h>
    
    int main(int argv, char* argc[])
    {
        printf("argv is %d
    ", argv);
        return 0;
    }

    先把文件编译  然后运行  

    [root@lyy les3]# gcc main.c -o m2.out
    [root@lyy les3]# ls
    m2.out  main.c  main.out
    [root@lyy les3]# ./m2.out -l -a
    argv is 3
    [root@lyy les3]# ./m2.out -l
    argv is 2

    argc

    main.c代码:

    #include <stdio.h>
    
    int main(int argv, char* argc[])
    {
        printf("argv is %d
    ", argv);
        int i;
        for(i=0;i<argv;i++)
        {
            printf("argc[%d] is %s
    ",i,argc[i]);
        }
        return 0;
    }

    编译后运行  并加上参数

    [root@lyy les3]# gcc main.c -o m3.out
    [root@lyy les3]# ls
    m2.out  m3.out  main.c  main.out
    [root@lyy les3]# ./m3.out -l -a asdfasf fdsaf
    argv is 5
    argc[0] is ./m3.out
    argc[1] is -l
    argc[2] is -a
    argc[3] is asdfasf
    argc[4] is fdsaf
  • 相关阅读:
    问题 K: 找点
    问题 B: 喷水装置(二)(在c++上运行有错误,提交AC了)
    问题 A: 喷水装置(一)
    问题 Q: 最大的数
    问题 O: 寻找最大数(三)
    96.n-1位数
    问题 K: A/B Problem
    问题 D: 某种序列
    被限制的加法
    1031苹果分级
  • 原文地址:https://www.cnblogs.com/jasonLiu2018/p/11484242.html
Copyright © 2011-2022 走看看