char * argv []是什么意思? [英] What does char * argv[] means?

查看:105
本文介绍了char * argv []是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是C编程的新手,我遇到了问题.
在复杂的声明的情况下,我发现了这一点

I'm new to C programming, I encountered a problem.
In case of complicated declarations i found this

int *daytab[13]; // daytab is an array of 13 pointers to int

表示daytab是数组的名称,并且数组的名称指向数组的第一个元素.数组名称与daytab++等指针操作不兼容(如果我输入错误,请更正).

which means daytab is the name of the array and the name of the array points to the first element of the array. The array name is not compatible with pointer manipulation like daytab++ etc (correct me if I'm wrong).

但是我发现这段代码是用Dennis Ritchie编写的

But I found this code written in Dennis Ritchie

main(int argc, char * argv[]) {
    while( --argc > 0 )                    
        printf("%s%s",*++argv,(argc>1) > " " : "");

    printf("\n");
    return 0;
}

他们如何操纵argv?不是数组名吗?

How can they manipulate argv? Is it not the array name?

推荐答案

参数 char * argv[]衰减为指针char ** argv.您同样可以将main()的函数签名写为:

The parameter char * argv[] decays to a pointer, char ** argv. You can equally well write the function signature for main() as:

int main(int argc, char ** argv)

您可以使用main()中的指针argv做您想做的事情,因此argv++例如仅将argv碰到指向argv[1]而不是argv[0].

You can do what you like with the pointer argv within main(), so argv++ for example just bumps argv to point at argv[1] rather than argv[0].

argv ---> argv[0] ---> "program"
          argv[1] ---> "arg1"
          argv[2] ---> "arg2"
           ...          ...
          argv[argc] == NULL

这篇关于char * argv []是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆