I currently have the dynamic array:
我目前有动态数组:
char *myData[500][10]; //myData is the name of an array of[500][10] pointers to type char.
I would like to create a static 2d array, 500 rows X 10 columns, each element storing memory for 40 characters.
我想创建一个静态2d数组,500行X 10列,每个元素存储40个字符的内存。
Would below be the correct way of declaring that?
以下是宣布这一点的正确方法吗?
char myData[500][10][40];
1 个解决方案
#1
Yes.
But:
- This is a large structure, and declaring it on the stack may not be a good idea
- This approach has less flexibility that the dynamic version
- if you mean to use NULL terminated strings with up to 40 characters of data, you should use
[500][10][41]
to leave room for the\0
这是一个大型结构,在堆栈上声明它可能不是一个好主意
这种方法的动态版本灵活性较低
如果你的意思是使用带有最多40个字符数据的NULL终止字符串,你应该使用[500] [10] [41]为\ 0留出空间
#1
Yes.
But:
- This is a large structure, and declaring it on the stack may not be a good idea
- This approach has less flexibility that the dynamic version
- if you mean to use NULL terminated strings with up to 40 characters of data, you should use
[500][10][41]
to leave room for the\0
这是一个大型结构,在堆栈上声明它可能不是一个好主意
这种方法的动态版本灵活性较低
如果你的意思是使用带有最多40个字符数据的NULL终止字符串,你应该使用[500] [10] [41]为\ 0留出空间