Decide the starting number to put at current position : If length is 0 , then there are no previous elements in arr [ ] . So start putting new numbers with 1. If length is not 0 , then start from value of previous element plus 1.
int i = ( len == 0 ) ? 1 : arr [ len - 1 ] + 1 ;