Hi everybody,
I'm starting learning C++ and I don't understand why this code for mirroring a array is not working.
All kinds of help would be very appreciated.
#include <iostream>
void mirror (int v[],int n){
int s;
int temp;
for (s=0;s<n;s++){
temp=v[s];
v[s]=v[n-1-s];
v[n-1-s]=temp;
}
}
int main()
{
int i=0;
int h[]={2,3,4,7,8,9};
mirror(h,6);
for (i=0;i<6;i++){
std::cout <<h[i]<<'\n';
}
return 0;
}
Thanks for your help, I know where my mistake is now! And I didn't know that about the vectors, I was just referring to a one-row array, also helpful information.
its a flaw. C++ should not have named vectors (the container) after a thing defined in math. They sort of can be a math vector, but they are really a generic container that could be a real vector. Meanwhile they renamed several pointless things (like null, which was just fine) and left vector (which is somewhat bad).