_HossamYehia_'s blog

By _HossamYehia_, history, 5 years ago, In English

This loop must ends at i = 3

https://ideone.com/Bt6d8F

I know the reason of Runtime error, because the last iteration access an index out of array.

But how i becomes greater than 2 ?!!

  • Vote: I like it
  • +18
  • Vote: I do not like it

| Write comment?
»
5 years ago, # |
  Vote: I like it +3 Vote: I do not like it
if(arr[i] > arr[i + 1]);

For i=2 you're accessing arr[3] here, which is Undefined Behavior.