I just saw the following code among the successful submissions at codechef.
http://www.codechef.com/viewplaintext/1595846
I used to think that
float max(int n,int arr[n][n])
{....}
is not allowed in C++ (as 'n' is a variable). My CodeBlocks (on windows) with MinGW [gcc 4.4] gives compile time error. that "error: array bound is not an integer constant.
Then how can be such a solution be accepted by CodeChef's judge. Is there any special flag that allows us to do that in C++???
EDIT: A link showing status as AC (accepted) : http://www.codechef.com/viewsolution/1595846
Most code and explanations are for a constant size of the array. In my function A I declare the variable and then I manipulate it a bit, and then it must be passed to Function B . You pass it as a variable to the function, like you have done in the question.
In this tutorial, we will learn how to pass a single-dimensional and multidimensional array as a function parameter in C++ with the help of examples. In C++, we can pass arrays as an argument to a function. And, also we can return arrays from a function.
Variable-length automatic arrays are allowed in ISO C99, and as an extension GCC accepts them in C90 mode and in C++. These arrays are declared like any other automatic arrays, but with a length that is not a constant expression.
Ref: http://gcc.gnu.org/onlinedocs/gcc/Variable-Length.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With