Hello. Is it possible to create an 8 dimensional array in C?
If no, then what can I do to improvise or let say bypass the limit?
Thanks in advance!
Hello. Is it possible to create an 8 dimensional array in C?
If no, then what can I do to improvise or let say bypass the limit?
Thanks in advance!
Should be no problem. Go ahead and create it!
Perhaps there's a better way to accomplish what you're doing. Would you care to explain what it is you want to do?
AFAIK, there is no upper limit on array rank in C, but it may get confusing and cumbersome during coding to refer to or use it correctly.
I am trying to create an 8 dimensional character array. And store some letters in it.
I tried 8 dimensional array (string). But compiler says "size of array 'letter' is too large". I am using DEV-C++ as my IDE and MinGW GCC 4.8.1 as my compiler. What should I do?
More or less. The memory usage of arrays with that many dimensions can easily be significant, and easily exceed the total addressable memory on modern machines. There aren't many ways around that.
More generally, however, as Matticus gently hinted with a question, using multidimensional arrays is usually a sign of not having thought much about a design (for example, storing large amounts of data in memory in order to sift through it, rather than accessing data in smarter and more efficient ways from a file).
Approach the problem with a different algorithm. Please describe in words why you need an array with 8 dimensions to store characters. Individual characters or null terminated strings? What will the application do?
The compiler should not be a factor.
Why 8?
char universe[COUNTRIES][CITIES][LIBRARIES][BOOKS][PAGES][PARAGRAPHS][SENTENCES][WORDLEN];
None of these dimensions is anywhere near constant.
Your array (assuming you can allocate it) will be full of huge holes where no data will be present.
Something fairly trivial like char a[10][10][10][10][10][10][10][10]; takes up 100MB of memory.
Just multiply all the dimensions together, and see how large the number is.
Think about your data again, and look up what a "sparse datastructure" is.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.