Note: use the github provided TOC for navigaing.
main concept of two pointer is if current sum is not equal to
int main(){
int arr[1000] = {1,2,3}; // array should be sorted
int n = 3;
int key;
cin>>key;
for (int i = 0; i < n; ++i){
/* code */
cin>>arr[i];
}
int i = 0;
int j = sizeof(arr)/sizeof(int);
while(i<j){
int current_sum = arr[i] + arr[j];
if(current_sum>key){
j--;
}
else if(current_sum<key){
i++;
}
else{
cout<<arr[i]<<" "<<arr[j];
i++;
j--;
}
}
}