for(int i=0;i<n;i++)
i starts with 0, so for the first time
i=0
j=i
and again for the first time a[j-1]will be [ (0 - 1)] = a [ -1] here
while((temp<a[j-1]) && (j>=0)) // array index starts from 0
hence the exception
therefore he must be
while((j>0) && (temp<a[j-1]) )
(&), , .