不要交错数组在C / C ++的存在? [英] Do jagged arrays exist in C/C++?
本文介绍了不要交错数组在C / C ++的存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有这样的事情在C或C ++交错数组?
当我编译如下:
INT锯齿状[] [] = {{0,1},{1,2,3}};
我得到这个错误:
错误:`锯齿作为多维数组的声明必须为所有的维界除了第一个
块引用>解决方案在C我会用一个指针数组。
例如:
为int *锯齿状的[5];锯齿状[0] = malloc的(的sizeof(int)的* 10);
锯齿状[1] = malloc的(的sizeof(int)的* 3);等等等等。
Is there such a thing as a jagged array in C or C++?
When I compile this:
int jagged[][] = { {0,1}, {1,2,3} };
I get this error:
error: declaration of `jagged' as multidimensional array must have bounds for all dimensions except the first
解决方案In C I would use an array of pointers.
For instance:
int *jagged[5]; jagged[0] = malloc(sizeof(int) * 10); jagged[1] = malloc(sizeof(int) * 3);
etc etc.
这篇关于不要交错数组在C / C ++的存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文