0
How to print out the last 5 values added to an array?
Let say I make an array of 10 elements and want to print the values of the 5 most recently added elements. Sure, I could print out the half but if it were an array of 20 elements, it wouldn’t work. What should I do? Sorry if I’m not asking this right. I just don’t know how to properly ask for it.
1 Resposta
+ 5
use simple for, but iterate in reversed order OR start from the array size -5 like:
for (int i = arraySize-5; i < arraySize; ++i)
{
//do something
}