I want a function in cpp that will return reversed array.. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I want a function in cpp that will return reversed array..

If I take array A from main function and pass to function .. In that function i want to create new array that will store reversed elements. And a function will return that reversed array.. I want to print reverse array in main function..

28th Jan 2020, 8:43 AM
Sahil Yadav
4 Answers
+ 5
cpp already has a function like this. use #include<algorithm> and call std:: reverse(iterrable.begin(), iterrable.end());
28th Jan 2020, 8:58 AM
grdr
+ 4
You can define it with only 10 lines of code.
28th Jan 2020, 8:55 AM
Seb TheS
Seb TheS - avatar
+ 3
There are several tutorials on creating functions such as reverse, strip, chop, tolowercase, etc. All of them use a for loop and manipulate each character using conditionals. Google them out. They are pretty handy
28th Jan 2020, 10:15 AM
Fernando Pozzetti
Fernando Pozzetti - avatar
0
Loop up how to return an array from a function first.... https://www.tutorialspoint.com/cplusplus/cpp_return_arrays_from_functions.htm then.... in that function...use reverse_copy from the algorithm header file. http://www.cplusplus.com/reference/algorithm/reverse_copy/
28th Jan 2020, 11:39 AM
rodwynnejones
rodwynnejones - avatar