关于指针定义的问题 [英] question about pointer define

查看:56
本文介绍了关于指针定义的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我对指针定义感到困惑,例如int *(p [3]);


它似乎括号接近p [3],它只定义了3个整数。

的明星

是没用的。它可以通过我的程序显示:


int main()

{

int *(p [3]);

// cout<< * p [0]<< " \t" << * p [1]<< " \t" << * p [2]<< endl;

cout<< & p [0]<< " \t" << & p [1]<< " \t" << & p [2]<< endl;

cout<< p [0]<< " \t" << p [1]<< " \t" << p [2]<<结束;

}


该程序可以通过g ++在cygwin linux上编译并运行,输出

是:


0x22efb0 0x22efb4 0x22efb8

0x76c 0xffffffff 0x22efc8




将是:


1900 -1 2289608


这正是上一个程序的十进制数。


第二行是注释掉,因为如果你想要
$ b,它将被核心倾销$ b get

指针的内容。


有人能解释一下这里发生了什么吗?谢谢。

Hello,

I''m confused by the pointer definition such as int *(p[3]);

It seems if the parenthesis close p[3], it defines only 3 integers. The
star
is just useless. It can be showed by my program:

int main()
{
int *(p[3]);
// cout << *p[0] << "\t" << *p[1] << "\t" << *p[2] << endl;
cout << &p[0] << "\t" << &p[1] << "\t" << &p[2] << endl;
cout << p[0] << "\t" << p[1] << "\t" << p[2] << endl;
}

The program can be compiled on cygwin linux by g++ and run, the output
is:

0x22efb0 0x22efb4 0x22efb8
0x76c 0xffffffff 0x22efc8

If you delete the * in the definition, define int (p[3]); the second
line
will be:

1900 -1 2289608

Which is exactly the decimal numbers of the the previous program.

The second line is comment-out, coz it''ll be core dumped if you want to
get
the content of the pointer.

Could someone explain what''s going on here? Thanks.

推荐答案

Wonder在08/09/05写道:
Wonder wrote on 08/09/05 :
// cout<< ; * p [0]<< " \t" << * p [1]<< " \t" << * p [2]<< endl;
cout<< & p [0]<< " \t" << & p [1]<< " \t" << & p [2]<< endl;
cout<< p [0]<< " \t" << p [1]<< " \t" << p [2]<< endl;
// cout << *p[0] << "\t" << *p[1] << "\t" << *p[2] << endl;
cout << &p[0] << "\t" << &p[1] << "\t" << &p[2] << endl;
cout << p[0] << "\t" << p[1] << "\t" << p[2] << endl;




不是C代码。 C ++就在隔壁。


-

Emmanuel

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

C库: http:// www .dinkumware.com / refxc.html


今天世界上有10种类型的人;

了解二元的人,那些不要。



Not a C-code. C++ is next door.

--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html

"There are 10 types of people in the world today;
those that understand binary, and those that dont."


我只是用cout来输出。这与问题的性质无关。这是一个问题。

我是新来的,不知道我们必须编写严格的C代码。

i''m just using cout to output. It has nothing to do with the nature of
the question here.
I''m new here, don''t know we have to write strict C code.


" Wonder" < SA ****** @ gmail.com>写道:
"Wonder" <sa******@gmail.com> wrote:
我对指针定义感到困惑,比如int *(p [3]);

看来如果括号关闭p [3],它仅定义3个整数。


编号p是一个由三个指针组成的数组。

这颗星是没用的。


绝对不是。括号是。

它可以通过我的程序显示:

int main()
{
int *(p [3]);
// cout<< * p [0]<< " \t" << * p [1]<< " \t" << * p [2]<< endl;
I''m confused by the pointer definition such as int *(p[3]);

It seems if the parenthesis close p[3], it defines only 3 integers.
No. p is an array of three pointers to int.
The star is just useless.
Definitely not. The parentheses are.
It can be showed by my program:

int main()
{
int *(p[3]);
// cout << *p[0] << "\t" << *p[1] << "\t" << *p[2] << endl;



< snip>


这绝不是C程序。要么用C重写,要么把它带到

comp.lang.c ++。


祝你好运

-

Irrwahn Grausewitz(ir*******@freenet.de)

欢迎来到clc: http://www.ungerhu.com/jxh/clc.welcome.txt

clc faq -list: http://www.faqs.org/faqs/ C-faq / faq /

clc常见答案: http://benpfaff.org/writings/clc


<snip>

This is by no means a C program. Either rewrite in C, or take this to
comp.lang.c++, please.

Best regards
--
Irrwahn Grausewitz (ir*******@freenet.de)
welcome to clc : http://www.ungerhu.com/jxh/clc.welcome.txt
clc faq-list : http://www.faqs.org/faqs/C-faq/faq/
clc frequent answers: http://benpfaff.org/writings/clc.


这篇关于关于指针定义的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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