什么是“int(* p)[3]”意思是如何使用它? [英] What does "int (*p)[3]" mean and how to use it?

查看:419
本文介绍了什么是“int(* p)[3]”意思是如何使用它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道int * p [3]意味着指向int的指针数组,但我遇到了这个令人困惑的
(* p)[3]。

它是什么意思以及如何使用它?感谢您的帮助。

I know int *p[3] mean an array of pointers to int, but I meet int
(*p)[3] which is confusing.
What does it mean and how to use it? Thanks for help.

推荐答案

hn ******** @ gmail.com 写道:

我知道int * p [3]表示一个指针数组int,但我遇到了这个令人困惑的
(* p)[3]。

这意味着什么以及如何使用它?感谢帮助。
I know int *p[3] mean an array of pointers to int, but I meet int
(*p)[3] which is confusing.
What does it mean and how to use it? Thanks for help.



int(* p)[3]将p声明为指向大小为3的int数组的指针。


例如:


#include< stdio.h>

#include< stdlib.h>


int main(void)

{

int(* p)[3];

int foo [3] = {0,1, 2};

p =& foo;


printf("%d - %d - %d \ n",(* p )[0],(* p)[1],(* p)[2]);


返回EXIT_SUCCESS;

}


PS:请查看常见问题解答以获得更好的解释。

int (*p)[3] declares p as a pointer to an array of int of size 3.

example:

#include <stdio.h>
#include <stdlib.h>

int main (void)
{
int (*p)[3];
int foo[3] = {0, 1, 2};
p = &foo;

printf(" %d -- %d -- %d\n", (*p)[0], (*p)[1], (*p)[2]);

return EXIT_SUCCESS;
}

PS: Please look into the FAQ for better explanation.


是(* p)[?]等于foo [ ?]这里?

i可以使用(* p)[?]在任何地方使用foo [?]?

i意味着我可以用(* p)替换所有foo [?] )[?]如我宣布的那样lang

"

int(* p)[3];

int foo [3] = {0,1,2};

p =& foo;


"
p _ *********** @ yahoo.co.in 写道:
is (*p)[?] equals to foo[?] here?
i can use (*p)[?] anywhere i used foo[?] ?
i mean can i replace all foo[?] with (*p)[?] as lang as i declared
"
int (*p)[3];
int foo[3] = {0, 1, 2};
p = &foo;

"
p_***********@yahoo.co.in wrote:
hn********@gmail.com 写道:

我知道int * p [3]表示指向int的指针数组,但是我遇到了这个令人困惑的
(* p)[3]。 br />
这意味着什么以及如何使用它?感谢帮助。
I know int *p[3] mean an array of pointers to int, but I meet int
(*p)[3] which is confusing.
What does it mean and how to use it? Thanks for help.



int(* p)[3]将p声明为指向大小为3的int数组的指针。


例如:


#include< stdio.h>

#include< stdlib.h>


int main(void)

{

int(* p)[3];

int foo [3] = {0,1, 2};


p =& foo;


printf("%d - %d - %d \ n" ,(* p)[0],(* p)[1],(* p)[2]);


返回EXIT_SUCCESS;

}


PS:请查看常见问题解答以获得更好的解释。


int (*p)[3] declares p as a pointer to an array of int of size 3.

example:

#include <stdio.h>
#include <stdlib.h>

int main (void)
{
int (*p)[3];
int foo[3] = {0, 1, 2};
p = &foo;

printf(" %d -- %d -- %d\n", (*p)[0], (*p)[1], (*p)[2]);

return EXIT_SUCCESS;
}

PS: Please look into the FAQ for better explanation.


p _ *** ********@yahoo.co.in 说:


< snip>
p_***********@yahoo.co.in said:

<snip>

>

int(* p)[3]将p声明为指向大小为3的int数组的指针。 />

例如:


#include< stdio.h>

#include< stdlib.h>


int main(无效)

{

int(* p)[3];

int foo [3] = {0,1,2};


p =& foo;
>
int (*p)[3] declares p as a pointer to an array of int of size 3.

example:

#include <stdio.h>
#include <stdlib.h>

int main (void)
{
int (*p)[3];
int foo[3] = {0, 1, 2};
p = &foo;



到目前为止一直这么好......

So far so good...


printf("%d - %d - - %d \ n,(* p)[0],(* p)[1],(* p)[2]);
printf(" %d -- %d -- %d\n", (*p)[0], (*p)[1], (*p)[2]);



如果使用%p,printf可以打印无效指针值,但就是这样。所以

以上的行应该是:


printf("%p - %p - %p \ n",(void *) (* p)[0],

(void *)(* p)[1],

(void *)(* p)[2]); < br $>

(格式化!)


-

Richard Heathfield

" ; Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk

电子邮件:rjh在上述域名中, - www。

printf can print void pointer values if you use %p, but that''s it. So the
above line should read:

printf(" %p -- %p -- %p\n", (void *)(*p)[0],
(void *)(*p)[1],
(void *)(*p)[2]);

(Format to taste!)

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.


这篇关于什么是“int(* p)[3]”意思是如何使用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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