First it would be better if you initialize the variables that are used in the loop within the loop itself. It helps in curbing unnecessary initializing issues.
Secondly, in your for loop, every time your increment by 2, so for an array of odd length say 3, i gets initialized to 0. Then in the next iteration it gets initialized to 2, and your loop tries to access i+1 , which is basically non- existing here ( as i+1 = 3, and an array of size would’ve index till 2 only.)