I have some images which I update like below:

if(count >= sizeOfArray)
    count = 0;
for(u32 i=0; i<sizeOfArray; i++)

I want to know, how do I reverse it. I mean, it is increasing the count and I want to decrease it. The sizeOfArray is 4.

Thanks in advance.

Just change the loop so that i is initialized to sizeOfArray-1, and loop until i == 0

Could you kindly elaborate a little please. When I reverse the code it decreases but once it excceds 0 the programe crashes and the count shows on output this number -

Count: 4294967295


The problem is here:

if(m <= 0)
    m = 4;

The output:

M: 4294967295

But it works with m++. Can anyone tell me why it does not work in c++?

The problem you are having is that you are using an unsigned integer type. When you underflow that type it wraps around to the largest number it can be. You have to be very careful when you get towards the min or max number that your type can hold because sometimes this will happen. One nice feature of this is that if you want the largest number that an unsigned type can hold you can always subtract one from 0 and you will get the max.

Unsigned int: 0 - 1 = 4294967295

Unsigned int: 4294967295 + 1 = 0

Ya, took me a little time to understand the problem. I realise I did not provide required information in my question. The sizeOfArray should not be = 4. Thats why it was crashing.

Thanks for the input.