Doubt in Binary Search

Could you please tell the test case or the missing condition in which my Binary Search code is failing?

int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);

int test=1;
//cin >> test;
while (test--) {
    int n;
    cin >> n;
    int arr[n];

    for (int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }
    int x;
    cin >> x;
    int l = 0, r = n - 1;
    bool found = false;
    while (l <= r)
    {
        int mid = (l + r) / 2;
        if (arr[mid] > x)
        {
            r = mid - 1;
        }
        else if (arr[mid] < x)
        {
            l = mid + 1;
        }
        else
        {
            cout << mid + 1 << endl;
            found = true;
            break;
        }
    }

    if (found == false)
    {
        cout << -1 << endl;
    }


}
return 0;

}