(Spiral print anticlockwise)Facing problem in passing 2d array as argument

void spiralanti(int m , int n, int arr[m][n])
error: use of parameter outside function body before ‘]’ token void spiralanti(int m,int n,int arr[m][n])
https://ide.codingblocks.com/s/52935

Hey Mohit, you have made some small mistakes in your code

  1. The function you have written is named spriralanti() but the function which you have called in main() is spiralanti(). The name of the function should be same when you declare and when you call it.
  2. you can’t pass a 2D array argument to a function with variable rows and columns like this int arr[m][n], so update it as int arr[10][10] (here 10 is used because in constraints it is mentioned that maximum limit for m and n will be 10).
  3. your output should exactly match the given output format, so update your print statements and give the space after ", " not before.
    I have updated your code you can refer this.
1 Like

Hey there. Thank you for the reply! I was wondering if there is any way of saving up on space and allocate only required amount of memory to 2d array?

Hey Mohit, yes you can definitely do that, for allocating only required space you can use pointer to a pointer approach. You can refer this I have just written an example of pointer to a pointer approach.

1 Like

Hey Mohit, as you are not responding to this thread, I am marking your doubt as Resolved for now. Re-open it if required.