When I try to run this
int N=10000000; short res[N];
I get segmentation fault 11
when I change to
int N=1000000; short
You can't allocate all that on the stack. Try short* res = new short[10000000]; and don't forget to clean up.
short* res = new short[10000000];
Alternatively, you can use std::vector res(10000000);
std::vector res(10000000);