BINARY SEARCH of element; i am unable to find mistake please help

#include<bits/stdc++.h>
using namespace std;
int main()
{
int T,t;
cin>>T;
for(t=0;t<T;t++)
{
int m=0,i,k=0,n,j,p;
cin>>n;
cin>>k;
int a[n];
for(i=0;i<n;i++)
{
cin>>a[i];
}
m=n/2;
if(a[m]==k)
{
cout<<m;
}
else if(a[m]<k)
{
for(j=(m+1);j<n;j++)
{
if(a[j]==k)
{
cout<<j;
}
}
}
else if(a[m]>k)
{
for(p=0;p<(m-1);p++)
{
if(a[p]==k)
{
cout<<p;
}
}
}
else
{
cout<<-1;
}
}
return 0;
}

This is not binary search and your linear search has a problem. It should be p<=(m-1) in the last for loop.