标题:[求助]c++ syntax about 2d array
只看楼主
aipb2007
Rank: 8Rank: 8
来 自:CQU
等 级:贵宾
威 望:40
帖 子:2879
专家分:7
注 册:2007-3-18
得分:0 
以下是引用HJin在2007-6-22 23:38:58的发言:
野比's way

[CODE]int* b=&a[0][0]; //a pointer to the start of the array
int** c=&b; //a pointer points to the pointer which points to the array... wow.....tongue twister... (^^!)
//now you can use the c pointer as the parameter of f() instead...[/CODE]

on my system gives access violation error. b points to the start of the 2d array, c is just the address of the b variable, so that

[CODE]c[2][2] = 1;[/CODE]
fails.




I think you misunderstand.
int *p[n];
p[n] = &a[0][0]
……

then
int **ptr = p;

try this.


Fight  to win  or  die...
2007-06-22 23:46
野比
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:24
帖 子:1627
专家分:516
注 册:2007-5-24
得分:0 
以下是引用HJin在2007-6-22 23:38:58的发言:
野比's way

[CODE]int* b=&a[0][0]; //a pointer to the start of the array
int** c=&b; //a pointer points to the pointer which points to the array... wow.....tongue twister... (^^!)
//now you can use the c pointer as the parameter of f() instead...[/CODE]

on my system gives access violation error. b points to the start of the 2d array, c is just the address of the b variable, so that

[CODE]c[2][2] = 1;[/CODE]
fails.

Hey budy, I posted a new method on the 7th floor.. SEE ?

Take a look..


女侠,约吗?
2007-06-24 23:10
HJin
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:401
专家分:0
注 册:2007-6-9
得分:0 
thanks 野比 and aipb2007, got your guys' idea.

I am working on a system which has no Chinese input. Please don\'t blame me for typing English.
2007-06-25 01:54
野比
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:24
帖 子:1627
专家分:516
注 册:2007-5-24
得分:0 
Not at all...

女侠,约吗?
2007-06-25 19:51



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-149238-1-1.html




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

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