• 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
  • 相关阅读:
    Python学习摘要201802
    机器学习-梯度下降参数调优小结
    用尽洪荒之力学习Flask源码
    Flask类的属性和方法大全
    Flask第三方工具组件介绍
    Flask自带的常用组件介绍
    Centos下部署Flask
    Python Tips阅读摘要
    web程序设计关于我们
    软工实践总结
  • 原文地址:https://www.cnblogs.com/jasonLiu2018/p/11484242.html
Copyright © 2020-2023  润新知