im having difficulties understanding how to make a function using 2d array. i just want to to call that function to show my 2d matrix where the user will input the size and it will adjust according to it. i read somewhere that there many ways and use vectors and pointers but i still havent study that since im new to c++.
what is the simplest way to do it? here is my code and i just copy the function somewhere. i think is called by array function by reference?
You can't declare array size at runtime like this in standard C++: int array[size][size];
(Some compilers allow it, partly because it is legitimate in the C99 version of C or allocatable arrays in fortran).
Either use dynamic arrays (with new and delete) or use vectors.
Personally, I prefer to map to 1-d arrays, since the storage for your 2-d array would be contiguous. However, the following would work. I've transferred the templating to the type of elements in the array and passed the sizes as function arguments.
im currently using dev c++ and didn't know that i cant use this kind of decleration int array[size][size]; , i'll keep this in mind. i see so i have to look into vectors so that i can input sizes of the 2d array. thanks again for your help.
@JLBorges thank you for the link and will read it now. kind of surprise that creating a function for displaying 2d array so that my main function wil look clean will make things complicated. thank you and i will study more.
On Unix/Linux, install a reasonably recent version of the GNU or LLVM compiler; precisely how to do this varies.
For example, to install g++ 7.3 on FreeBSD, as root: cd /usr/ports/lang/gcc7/ && make install clean (bootstrap build from source)
or pkg install gcc7 (install binary)