I was going through the examples for std::transform() function for c++ under STL, from this link ,
what I understood is , it is used to add two arrays and saves them in a result (res here).
So I tried to limit the size of res by size 1 (res[0]) , and I was expecting some compile time error as in below for loop it is trying to extract i < n , (n = 3 here, which would be index out of range).
But i has incremented 8 times in my program.
Could someone please explain me the reason , one more thing, is transform is similar to python's res = [x+y for x,y in zip(arr1,arr2)] , thanks in Advance :).
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int arr1[]= {1,2,3};
int arr2[]= {4,5,6,7}; // should be greater than arr1 size
int n = sizeof(arr1)/sizeof(arr1[0]);
cout<<"n = "<<n<<endl;
int res[0];
cout<<"res[0] = "<<res[0]<<endl;
transform(arr1,arr1+n,arr2, res, plus<int>());
for(int i= 0; i < n; i++) {
cout<<"i = "<<i<<" res[i] = "<<res[i]<<endl;
}
cout<<endl;
return 0;
}

resis a zero sized array which is not allowed. All indexing of it will be out of bounds and lead to undefined behavior..ois for object files, not for executable files. Executable files in a POSIX environment (like Linux) traditionally doesn't have a suffix.