Why am i getting the following error:

ERROR: /bin/run.sh: line 4: 18 Segmentation fault (core dumped) ./exe

CODE:

#include
#include
using namespace std;

void swap(long int *xp, long int *yp)
{
long int temp = *xp;
*xp = *yp;
*yp = temp;
}

void selectionSort(long int arr[], long int n)
{
long int i, j, min_idx;

// One by one move boundary of unsorted subarray  
for (i = 0; i < n-1; i++)  
{  
    // Find the minimum element in unsorted array  
    min_idx = i;  
    for (j = i+1; j < n; j++)  
    if (arr[j] < arr[min_idx])  
        min_idx = j;  

    // Swap the found minimum element with the first element  
    swap(&arr[min_idx], &arr[i]);  
}  

}

int main()
{
long int arr[100000000],n;
cin>>n;
for(long int i=0 ; i<n ; i++)
{
cin>>arr[i];
}
selectionSort(arr, n);

for(int i=0 ; i<n ; i++)
cout <<arr[i]<<endl;  
return 0;  

}

@amangupta try reducing the array size to 1e5

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.