加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux c 的main 函数中的return 和 查看返回参数 argv 与 argc

发布时间:2020-12-14 00:40:44 所属栏目:Linux 来源:网络整理
导读:hello.c #include stdio.h int main( int argv, char * argc[]){ printf( " hello word!n " ); return 0 ;} ? 编译后? 直接运行? ? 作用为连接命令 gcc hello.c -o main. out ./main. out ? ? 再运行? 就查看返回参数 echo $? ? argv作用: main.c文件代码

hello.c

#include <stdio.h>

int main(int argv,char* argc[])
{
    printf("hello word!n");
    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 %dn",argv);
    return 0;
}

?

先把文件编译? 然后运行??

[[email?protected] les3]# gcc main.c -o m2.out
[[email?protected] les3]# ls
m2.out  main.c  main.out
[[email?protected] les3]# ./m2.out -l -a
argv is 3
[[email?protected] les3]# ./m2.out -l
argv is 2

?

argc

main.c代码:

#include <stdio.h>

int main(int argv,argv);
    int i;
    for(i=0;i<argv;i++)
    {
        printf("argc[%d] is %sn",i,argc[i]);
    }
    return 0;
}

编译后运行? 并加上参数

[[email?protected] les3]# gcc main.c -o m3.out
[[email?protected] les3]# ls
m2.out  m3.out  main.c  main.out
[[email?protected] 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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读