Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
mirrorpoint
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
//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; }
g++
Show compiler warnings
[
+
] Compiler args
[
+
]
Show input
Compilation time: 0.42 sec, absolute running time: 0.15 sec, cpu time: 0.01 sec, memory peak: 5 Mb, absolute service time: 0,63 sec
edit mode
|
history
|
discussion
2 3 4 5 6 7 7 6 5 4 3 2