Ram Prasad

Ram Prasad

  • NA
  • 326
  • 16.8k

System out of range exception at the end of the loop

Dec 31 2021 8:50 AM

System is giving me out of range exception when p = 255. My understading is that with "OR operator, later part of if statement shoudl come into affet. However, it is not. Please advise on how to fix it.

for (int p = 0; p < 256; p++) 
{    
    if (buffer[p] == buffer[p + 1] || buffer[p] == buffer[p - 1])
    {
        //Code
    }
}

 


Answers (7)