Does This 'for' Loop in C++ Cause an Error?

  • Context: C/C++ 
  • Thread starter Thread starter ineedhelpnow
  • Start date Start date
  • Tags Tags
    Loops
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
2 replies · 2K views
ineedhelpnow
Messages
649
Reaction score
0
does this result in an error?

for (i = 0; i < itemsLast.size(); ++i)
{
itemsList.at(i) = itemsList.at(i+1);
}
 
Physics news on Phys.org
Counting begins at zero, so if you have an array with $n$ elements, the index value for the last element is therefore $n-1$. So, does the loop result in an error?