I've used different values of n below and above 10^8. It works fine below it. But starts showing SIGSEGV once the input to n increases upto 10^8 or more. Why does this happen? My compiler is g++ 7.4.0
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
long long int n, k, c = 0;
cin >> n >> k;
long long int arr[n];
for(long long int i =1; i <=n ; i+=2){
arr[c] = i;
c++;
}
for(long long int j =2; j <=n ; j+=2){
arr[c] = j;
c++;
}
cout << arr[k-1];
return 0;
}