| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 5172 人关注过本帖
标题:myajax95斑竹,我要求你把那个帖子解开
只看楼主 加入收藏
wfpb
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:2188
专家分:0
注 册:2006-4-2
收藏
得分:0 

谢谢你对我int(*p)[5]这个问题的指教,在几个小时前,热情依然已经告诉我怎么回事了,我先前只是知道它的字面意思,现在知道它怎么用了,呵呵。

不管怎么说,谢谢你了。

不过其他的问题仍然是不存在的。

我只是在不清楚int(*p)[5]是个什么东西的情况下,才以为要动态分配内存,因为调试时它老是0x000000,
现在误会搞清楚了,但是和我们先前的观点是没有关系的,我对int(*p)[5]的误解,并不表示其他指针知识的缺乏,今天感谢热情依然和穆兄你,我知道了int(*p)[5]的完全用法。

你认为int *pt = new int[5];那个例子pt==0x000000有问题?
非要void*p=new int[5];才没问题?那么我想问下:(new int[5])这个东西是什么类型?
要记得,其实new int[5];相当于是返回一个int指针,只是因为void指针可以指向任何类型的对象,才能void*p=new int[5];如果有争议:请首先回答(new int[5])这个东西是什么类型?


[glow=255,red,2]wfpb的部落格[/glow] 学习成为生活的重要组成部分!
2006-07-24 19:19
kai
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:52
帖 子:3450
专家分:59
注 册:2004-4-25
收藏
得分:0 
I want say int (*)p[5] != int p[5]; they are not same.

first one ist point array, that mean an array for pointer, here will a place for 5*4 Byte allocated, notice this 20 Byte is not dynamicaly allocation. and then in p[0] ... p[4] you can assign a pointer there, that mean, p[0] can save a pointer value, p[1] too,... p[4] too.

And now look at int p[5], this is an integer array, that mean, in this array can only integer value saved.

自由,民主,平等,博爱,进步.
中华民国,我的祖国,中华民国万岁!中华民国加油!
本人自愿加入中国国民党,为人的自由性,独立性和平等性而奋斗!
2006-07-24 21:47
神vLinux飘飘
Rank: 13Rank: 13Rank: 13Rank: 13
来 自:浙江杭州
等 级:贵宾
威 望:91
帖 子:6140
专家分:217
注 册:2004-7-17
收藏
得分:0 
小小k又开始卖弄他的英文了,呵呵
有设么疑问,编译成汇编语言不都全部解决了么?

淘宝杜琨
2006-07-24 21:54
热情依然
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:22
帖 子:715
专家分:0
注 册:2005-4-5
收藏
得分:0 
哈哈,我还想听一下kai兄说一说关于Reference counting

c++/C + 汇编 = 天下无敌
2006-07-24 21:55
热情依然
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:22
帖 子:715
专家分:0
注 册:2005-4-5
收藏
得分:0 
以下是引用神vLinux飘飘在2006-7-24 21:54:59的发言:
小小k又开始卖弄他的英文了,呵呵
有设么疑问,编译成汇编语言不都全部解决了么?

正想学汇编


c++/C + 汇编 = 天下无敌
2006-07-24 21:56
神vLinux飘飘
Rank: 13Rank: 13Rank: 13Rank: 13
来 自:浙江杭州
等 级:贵宾
威 望:91
帖 子:6140
专家分:217
注 册:2004-7-17
收藏
得分:0 
我会,以前很多C语言不明白的地方,用WIN-TC编译成汇编一看就全清楚了

淘宝杜琨
2006-07-24 21:58
热情依然
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:22
帖 子:715
专家分:0
注 册:2005-4-5
收藏
得分:0 
以下是引用神vLinux飘飘在2006-7-24 21:58:26的发言:
我会,以前很多C语言不明白的地方,用WIN-TC编译成汇编一看就全清楚了

就是因为这样我才想学汇编


c++/C + 汇编 = 天下无敌
2006-07-24 22:06
穆扬
Rank: 1
等 级:禁止发言
帖 子:1910
专家分:0
注 册:2006-6-1
收藏
得分:0 
提示: 作者被禁止或删除 内容自动屏蔽

2006-07-24 22:09
kai
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:52
帖 子:3450
专家分:59
注 册:2004-4-25
收藏
得分:0 
you have all made a mistake. That is you all think the return type from new is void. That is wrong.

take a look there, that is a link from msdn: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclang/html/_pluslang_new_operator.asp

The correct is, the return type from new is a suitable type. And the return type from malloc is really (void *) . So please pay attention to this difference.

That is why int * p = new int; you don't need write so int * p = (int *) new int; of course you can write your code like this, but unnecessary. But when you use malloc then you must use type cast, why? Because the return type from malloc is (void *), so we must use type cast, code like this: int * p = (int *) malloc( sizeof (int));

[此贴子已经被作者于2006-7-24 22:13:30编辑过]


自由,民主,平等,博爱,进步.
中华民国,我的祖国,中华民国万岁!中华民国加油!
本人自愿加入中国国民党,为人的自由性,独立性和平等性而奋斗!
2006-07-24 22:09
穆扬
Rank: 1
等 级:禁止发言
帖 子:1910
专家分:0
注 册:2006-6-1
收藏
得分:0 
提示: 作者被禁止或删除 内容自动屏蔽

2006-07-24 22:13
快速回复:myajax95斑竹,我要求你把那个帖子解开
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016968 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved