免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1614 | 回复: 8

short (*block)[64] 与short *block[64]有什么 区别 [复制链接]

论坛徽章:
0
发表于 2005-12-05 10:04 |显示全部楼层
我遇到这两个定义,short (*block)[64] 与short  *block[64]     short (*blocks)[6][64] 但现在很糊涂他们的区别,能否用具体事例说明一下呢,谢谢各位了!

论坛徽章:
0
发表于 2005-12-05 10:11 |显示全部楼层
1. pointer to array 64 of short
2. array 64 pointer to short
3. pointer to array[6] [64] of short

论坛徽章:
0
发表于 2005-12-05 10:18 |显示全部楼层
谢谢!还想问一下,那他们动态分配空间,应该怎么写呢,在C和C++有不同,我不是很明确应该怎么用

论坛徽章:
0
发表于 2005-12-05 10:21 |显示全部楼层
short (*block)[64] 与short  *block[64]     short (*blocks)[6][64]
1、=malloc(sizeof(short)*64);
2、=不能直接分配
3、=malloc(sizeof(short)*64*6);
c用malloc,c++可以用new和malloc

论坛徽章:
0
发表于 2005-12-05 10:31 |显示全部楼层
多谢了! 我这样使用应该没错吧
short i,j;
short (*block)[64];
block = (short (*)[64]) malloc(sizeof(short)*64*10)   //c++要强制
for ( i = 0; i<10; i++ )
{
        for ( j = 0; j<64; j++ )
        {
                block[i][j] = j;
        }       
}

论坛徽章:
0
发表于 2005-12-05 10:34 |显示全部楼层
汗死,不对,自己想,低级错误

论坛徽章:
0
发表于 2005-12-05 10:44 |显示全部楼层
原帖由 hxdhxd_hxd 于 2005-12-5 10:31 发表
多谢了! 我这样使用应该没错吧
short i,j;
short (*block)[64];
block = (short (*)[64]) malloc(sizeof(short)*64*10)   //c++要强制
for ( i = 0; i<10; i++ )
{
        for ( j = 0; j<64; j++ ) ...



是因为 block = (short (*)[64]) malloc(sizeof(short)*64*10)    没加";" 吗,其他还有使用上的错误吗.我真的不知道了. 

论坛徽章:
0
发表于 2005-12-05 15:19 |显示全部楼层
http://www.watchina.org/html/program/56230.html

[ 本帖最后由 eastowen 于 2005-12-5 15:54 编辑 ]

论坛徽章:
0
发表于 2005-12-10 10:25 |显示全部楼层
谢谢!同志门.我要多学学了
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP