Two pointer approach

please elaborate how :

  1. int j = sizeof (a) / sizeof (int) - 1 works to give the last element.

  2. at the end we did i++ and j-- but we had done that in if conditions so why did we do it again

Hey @bhavaysinghal

This gives size of array in bytes = 4*no of elements
Now sizeof(int)=4bytes

Then int j=4*n/4-1==n-1

If sum ==target then we print the pair and then we should move i and j right
Because if we dont then sum==target always and will be stuck in an infinite loop