You approach would differ depending on the logic of your program, and also whether you are going with C or C++. (In most cases people will get very angry if you tag both. see)
If you have a set of many arrays, predefined at compile time, i.e., contains some data at the start of your program, you can define them in a header file with reasonable names. If you wish, you can prefix them with an identifier, like myMats_mat1
, for your matricies to avoid naming conflicts. C++ also presents a native way to accomplish this by namespace
s.
Normally though, you would have a cleaner, neater logic. For instance, if you have a large amount of data, like your many arrays with hundreds of elements, you usually would store that in a file (a regular text file, or a binary file), and have functions to read it and write back to local containers when they are needed. This also allows you to both separate your data from your code, and occupy less memory since you only would work with a presumably smaller subset of the data.
In most cases, you would also have multiple functions to do stuff with these arrays, perhaps you would have a function to compare two matricies, another to take determinant, another to sum all elements, whatever. You would also group these together in seperate .h
and .c
files together with your arrays (in the .h
file). Again depending on your program, you may not even need to access the arrays themselves in your main
function, and just call functions to do stuff on them. In such case, you can define your arrays as static
, restricting their scope to that particular file, hence not really putting them global scope.
In C++, you can also group them in a class, both your arrays and the related functions. Its basically the same idea as above, just the C++ way of implementing it.
I should stress that the ideas that I throw out there may be good, acceptable or outright horrible depending on your use case. Take all with a grain of salt.