Query on reverse()

Firstly,
we can use reverse using following syntax for 1D and 2D int array :-

int a[5]={0};
reverse(a,a+5);

int a[5][5]={0};
reverse(a[2],a[2]+5);

right?

secondly,
I’m getting error when i do following for 2D array:-
reverse(a[][2],a[][2]+5);

So, how to reverse a column using reverse() ?

hello @prerak_semwal
we cannot use reverse function to reverse 2d array columwise (because 2d array’s are stored in row major form).
ss
u have to write ur own function to reverse columnwise.

1 Like

@aman212yadav
First one ?

sry didnt get u what u r asking?

@aman212yadav

I have given two syntax for using reverse() on !D and 2d array, are they implemented correctly ?

only these syntax are correct.

this is incorrect becuase matrix are stored in row major form in c/c++ becuase of that reversing columwise using inbuilt function is not possible

1 Like

@aman212yadav

yes I got it. Thanks

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.