Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
mirrorpoint
//g++ 7.4.0 //write a function that is passed an array of n pointers to ints and returns a newly created array that contains those n int values in reverse order //this code is created by Rezaul Hoque on July 21,2021;contact: jewelmrh@yahoo.com //note: codes shared by Rezaul Hoque on rextester are not for sale; they are created and shared to facilitate the algorithm learning process; many like Hoque use this platform to practice programming ;Rezaul hopes his contribution helps others to fine tune their learning; #include <iostream> using namespace std; int* mirror(int * [],int); int* mirror(int* p[],int n){ int* point= new int[n]; for(int i= n;i>0;i--) point[i-1]=*p[n-i];//last index of point[] holds the first value indicated by p[]; as i decrements point traverses backward holding subsequent values pointed to by p[]; finally point[] points to reversed elements of the original array return point; } int main (){ int a[]={2,3,4,5,6,7}; int n=sizeof(a)/sizeof(a[0]); for(int i=0;i<n;i++){ cout<<" "<<*(a+i); } cout<<"\n"; int * p[n]; for(int i=0;i<n;i++) p[i]=&a[i]; int * b=mirror(p,n); for(int i=0;i<n;i++) cout<<" "<<*(b+i); return 0; }
run
|
edit
|
history
|
help
0
NonparaSign
Boost phoenix. e.g 3 phoenix: functor
sysFork3
simple calculator
VecHotel2
template example
funpointer
MyString
2
Some-stuff