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
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
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...

Similar threads

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