views:

149

answers:

1

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.

Would below be the correct way of declaring that?

char myData[500][10][40];
+5  A: 

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
dmckee