表示数组,其中每个元素是可变长度的数组 [英] Represent array where each element is an array of variable length
问题描述
我想在C中这样说:
python
I want to say like this in C :
python
[[0],[1],[0,1]]
我试图说明它的二维数组,arr [x] [y]但是我我被困了因为它需要相同的长度来代替y,即使我使用3D阵列我也有同样的问题。我可以用c说明这个吗?
谢谢
非常感谢帮助。
我尝试了什么:
我试图说出它的二维数组,arr [x] [y]但是我我被困了因为它需要相同的长度来代替y,即使我使用3D阵列我也有同样的问题。我可以在c中说明这个吗?
I tried to state that its two dimensional array, arr[x][y] but i'm stuck coz it requires same length to be used in place of y even if i use 3 d array i have same problem. can i state this in c anyways ?
Thanks
Help greatly appreciated.
What I have tried:
I tried to state that its two dimensional array, arr[x][y] but i'm stuck coz it requires same length to be used in place of y even if i use 3 d array i have same problem. can i state this in c anyways ?
推荐答案
我会用:
I'd use:
int *myArray[x];
然后用我的变量长度填充它:
And then populate it with my variable lengths:
for (i = 0; i < x; i++)
{
myArray[i] = (int*) malloc((i + 1) * 3 * sizeof(int));
}
我讨厌标记! :mad:[/ edit]
哎呀!忘了sizeof ... [/ edit]
[edit]I HATE MARKDOWN! :mad: [/edit]
[edit]Oops! Forgot the sizeof...[/edit]
这篇关于表示数组,其中每个元素是可变长度的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!