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

  • Thread starter Thread starter ineedhelpnow
  • Start date Start date
  • Tags Tags
    Loops
AI Thread Summary
The code snippet provided results in an error due to an out-of-bounds access. The loop iterates from 0 to the size of the array minus one, but the line `itemsList.at(i) = itemsList.at(i+1);` attempts to access an index that exceeds the array's bounds when `i` equals the last index. This leads to an attempt to access `itemsList.at(n)`, which is invalid, confirming that the loop will indeed result in an error.
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);
}
 
Technology 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?
 
Yes
 
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...

Similar threads

Replies
22
Views
3K
Replies
2
Views
908
Replies
1
Views
4K
Replies
4
Views
1K
Replies
5
Views
2K
Replies
1
Views
1K
Back
Top