Objective C 2d数组,Array下标不是整数

时间:2021-01-18 21:31:55

I'm trying to use a 2d array in Objective-C but getting an error of Array subscript is not an integer.

我正在尝试在Objective-C中使用2d数组,但是获取Array下标的错误不是整数。

NSUInteger grid[15][15];
NSUInteger x,y;

grid[x][y]=1;

I have tried changing from NSUInteger to NSInteger and int.

我尝试过从NSUInteger更改为NSInteger和int。

Can someone please tell me where am I going wrong?

有人可以告诉我哪里出错了?

Thanks

谢谢

1 个解决方案

#1


1  

You need to define a value for x and y, or else you're not accessing any index...

您需要为x和y定义一个值,否则您不会访问任何索引...

NSUInteger grid[15][15];
NSUInteger x=1,y=2;

grid[x][y]=1;

#1


1  

You need to define a value for x and y, or else you're not accessing any index...

您需要为x和y定义一个值,否则您不会访问任何索引...

NSUInteger grid[15][15];
NSUInteger x=1,y=2;

grid[x][y]=1;