Simple insertion sort : Why this code waits for user to input 10 integers when size of array input by user is 8 ? It gives segmentation fault when 10 integers are used.`

        #include<iostream>
    using namespace std;
    int main()
    {
    int x,a[x];
    cout<<"enter the size of array"<<endl;
    cin>>x;
    cout<<"enter the elements"<<endl;
    for(int j=0;j<x;j++)
    cin>>a[j];
    for(int i=1;i<x;i++){
    for(int k=0;k<i;k++){
    if(a[i]<a[k])
    swap(a[i],a[k]);
    else continue;
    }
    }
    for(int m=0;m<x;m++)
    cout<<a[m];
    }

