定义和初始化多维数组时出错 [英] Error defining and initializing multidimensional array
本文介绍了定义和初始化多维数组时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在编译时遇到以下定义的错误。
I get error in compilation with the following definition.
int matrix[ ][ ] = { { 1, 2, 3}, {4,5,6} };
char str[ ][ ] = { "abc", "fgh" };
为什么编译器抱怨缺少下标和太多的初始化器。
Why is the compiler complaining missing subscript and too many initializers.
推荐答案
在声明多维数组时,必须明确定义除最后一个维之外的所有维的大小。否则,编译器不知道如何在数组中找到给定的值。
When you declare a multi-dimensional array, you must explicitly define the size of all but the last dimension. Otherwise, the compiler won't know how to find a given value in the array.
编辑:阅读我的帖子这里
这篇关于定义和初始化多维数组时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文