char ** argv和char * argv []之间的差异 [英] difference(s) between char** argv and char* argv[]

查看:81
本文介绍了char ** argv和char * argv []之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

之间的区别是什么:


int main(int argc,char * argv []){

...

}


和:


int main(int argc,char ** argv){

...

}


似乎在第一个例子中,argv是一个char *数组并且在
$ b $中b第二个例子它是char *的指针?我的一本C书告诉我

差异是可怕的微妙但实际上并没有描述

有什么不同。我可以互换使用它们吗?

解决方案



2003年9月3日星期三,David写道:


之间的区别是什么:
int main(int argc,char * argv [])
int main(int argc,char ** argv )
似乎在第一个例子中,argv是一个char *数组,而在第二个例子中它是一个指向char *的指针?我的一本C书告诉我
差异是可怕的微妙但实际上并没有描述
有什么区别。我可以互换使用它们吗?




是的。他们完全相同。你已经多次被告知过这个问题,好几次是
,模仿Tisdale的泥泞。 [忽略他。]


bar_t foo(baz_t quux []);


完全等同于


bar_t foo(baz_t * quux);


在所有方面。


p []和* p之间的区别来自OUTSIDE函数原型,

其中,例如,


extern int arr [];


声明'' arr''属于类型''数组[未指定大小]的int'',

,也称为不完整的数组类型。由于''arr''的类型

是不完整的,所以你不能,例如,取数组''sizeof''

。相反,


extern int * ptr;


声明''ptr''是''指向int''的类型,并且并不完整。

也就是说,你可以像使用任何指针一样使用''ptr'',

当然包括''sizeof''它。


在你完成练习之前不要担心这些事情

在K& K的前五章中R(或等价物)。然后你就可以开始担心成为一名语言律师了。 :-)


HTH,

-Arthur


David写道:
< blockquote class =post_quotes>之间的区别是什么:

int main(int argc,char * argv []){
...
}

和:

int main(int argc,char ** argv){
...
}


没有差异。

似乎在第一个例子中,argv是一个char *
的数组

不,它是指向第一个的指针字符串数组中的元素。尽管出现了它的类型是

指向char的指针。


第二个例子它是指向char *的指针?


是的,在第二个例子中,argv是一个指向

字符串数组中第一个元素的指针。它的类型是指向char的指针。


读K& R2 pp99-100。

我的一本C书告诉我
差异是可怕的微妙的


那本书的作者要么是弄错了,要么撒谎 - 可能只是错误地认为是错误的。考虑到这是对着书的一个黑色标记,因为他确实应该知道这个。它是哪本书?

但实际上并没有描述
有什么区别。


没有。

我可以互换使用吗?




当然。它们具有相同的类型。这只是两种不同的方式来写同样的东西。

-

Richard Heathfield: bi **** @ eton.powernet.co.uk

Usenet是一个奇怪的地方。 - Dennis M Ritchie,1999年7月29日。

C FAQ: http://www.eskimo.com/~scs/C-faq/top.html

K& R答案,C书等:< a rel =nofollowhref =http://users.powernet.co.uk/etontarget =_ blank> http://users.powernet.co.uk/eton


Arthur J. O''Dwyer写道:

David写道:

what'' s之间的区别:

int main(int argc,char ** argv)



似乎在第一个例子中,argv是一个char *数组,在第二个例子中它是一个指向char *的指针?我的一本C书告诉我
差异非常微妙,但实际上并没有描述
有什么区别。我可以互换使用它们吗?



是的。他们完全相同。




请不要喊。

你已经多次告诉过这个,


大卫什么时候告诉过这个?

modulo Tisdale的混乱。 [忽略他。]

bar_t foo(baz_t quux []);

完全等同于

bar_t foo(baz_t * quux);

在所有方面。

p []和* p之间的区别来自OUTSIDE函数原型,


你可能意味着正式参数列表。

baz_t quux []和baz_t * quux在函数foo的*定义及其声明中表示同样的事情



其中,例如,

extern int arr [];

声明''arr''类型''数组[未指定大小]的int' ',
另外称为不完整阵列类型。由于''arr''的类型不完整,所以你不能,例如,取数组''sizeof''。相反,

extern int * ptr;

声明''ptr''是''指向int'的类型',并且不完整。
也就是说,你可以像使用任何指针一样使用''ptr',
当然包括''sizeof''它。

在K& R(或同等学历)的前五章中完成练习之前,不要担心这些事情。然后你可以开始担心成为一名语言律师。 : - )




请引用并引用您认为与David的问题最相关的常见问题解答




what''s the differences between:

int main(int argc,char* argv[]){
...
}

and:

int main(int argc,char** argv){
...
}

it seems that in the first example, argv is an array of char* and in
the second example it''s a pointer to char*? one of my C book tells me
that the difference is horriblly subtle but doesn''t actually discribe
what the difference is. i can use them interchangeablly right?

解决方案


On Wed, 3 Sep 2003, David wrote:


what''s the differences between:

int main(int argc,char* argv[]) int main(int argc,char** argv) it seems that in the first example, argv is an array of char* and in
the second example it''s a pointer to char*? one of my C book tells me
that the difference is horriblly subtle but doesn''t actually discribe
what the difference is. i can use them interchangeably right?



Yes. They''re EXACTLY THE SAME THING. You have already been told this,
several times, modulo Tisdale''s muddyings. [Ignore him.]

bar_t foo ( baz_t quux[] );

is exactly equivalent to

bar_t foo ( baz_t *quux );

in all respects.

The difference between p[] and *p comes OUTSIDE function prototypes,
where, for example,

extern int arr[];

declares ''arr'' to be of type ''array[unspecified size] of int'',
otherwise known as an "incomplete array type." Since the type
of ''arr'' is incomplete, you can''t, for example, take the ''sizeof''
the array. Contrariwise,

extern int *ptr;

declares ''ptr'' to be of type ''pointer to int'', and is not incomplete.
That is, you can use ''ptr'' in the same way you''d use any pointer,
including, of course, taking the ''sizeof'' it.

Just don''t worry about these things until you have done the exercises
in the first five chapters of K&R (or equivalent). Then you can
start worrying about becoming a language lawyer. :-)

HTH,
-Arthur


David wrote:

what''s the differences between:

int main(int argc,char* argv[]){
...
}

and:

int main(int argc,char** argv){
...
}
No differences.
it seems that in the first example, argv is an array of char*
No, it''s a pointer to the first element in an array of strings. Its type is
"pointer to pointer to char", despite appearances.
and in
the second example it''s a pointer to char*?
Yes, in the second example, argv is a pointer to the first element in an
array of strings. Its type is "pointer to pointer to char".

Read K&R2 pp99-100.
one of my C book tells me
that the difference is horriblly subtle
The author of that book is either mistaken or lying - probably just
mistaken. Consider that to be one black mark against the book, since he
really should have known this. Which book is it?
but doesn''t actually discribe
what the difference is.
There is none.
i can use them interchangeablly right?



Of course. They have the same type. These are just two different ways of
writing the same thing.
--
Richard Heathfield : bi****@eton.powernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton


Arthur J. O''Dwyer wrote:

David wrote:

what''s the differences between:

int main(int argc,char* argv[])

int main(int argc,char** argv)



it seems that in the first example, argv is an array of char* and in
the second example it''s a pointer to char*? one of my C book tells me
that the difference is horribly subtle but doesn''t actually describe
what the difference is. I can use them interchangeably right?



Yes. They''re EXACTLY THE SAME THING.



Please don''t shout.
You have already been told this, several times,
When was David told this?
modulo Tisdale''s muddying. [Ignore him.]

bar_t foo(baz_t quux[]);

is exactly equivalent to

bar_t foo(baz_t* quux);

in all respects.

The difference between p[] and *p comes OUTSIDE function prototypes,
You probably meant formal argument lists.
baz_t quux[] and baz_t* quux mean the same thing
in the *definition of function foo as well as in its declaration.
where, for example,

extern int arr[];

declares ''arr'' to be of type ''array[unspecified size] of int'',
otherwise known as an "incomplete array type." Since the type
of ''arr'' is incomplete, you can''t, for example, take the ''sizeof''
the array. Contrariwise,

extern int *ptr;

declares ''ptr'' to be of type ''pointer to int'', and is not incomplete.
That is, you can use ''ptr'' in the same way you''d use any pointer,
including, of course, taking the ''sizeof'' it.

Just don''t worry about these things until you have done the exercises
in the first five chapters of K&R (or equivalent). Then you can
start worrying about becoming a language lawyer. :-)



Please cite and quote the FAQ
that you believe is most relevant to David''s question.


这篇关于char ** argv和char * argv []之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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