Why is output coming wrong( its a target sum pairs question)

#include

using namespace std;

int main()
{
int a[10001];
int n{0},key{0};
int* leftptr{0};
int* rightptr{0};
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i];
}
cin>>key;
leftptr=a[0];
rightptr=&a[n-1];

while(leftptr < rightptr){
if((*leftptr) + (*rightptr)==key)
{
cout<<*leftptr<<" and "<<*rightptr<<endl;
leftptr++;
rightptr–;
}
else if((*leftptr)+(*rightptr)>key)
{
rightptr–;
}
else{
leftptr++;
}
}
}

@Shubham_helloworld
Paste your code in coding blocks ide and provide me the link.
(pasting the code directly on discuss alters it somewhat).

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.