How many times will this loop execute?

How many times will this loop execute? Explain your answer. unsigned char half_limit = 150; for (unsigned char i = 0; i < 2 * half_limit; ++i) { // do something; }


1 Answer
1-1 of  1
1 Answer
  • this code will result in an infinite loop. However since i is an unsigned char, it is represented by an 8-bit value which, after reaching 255, will overflow (so it will go back to 0) and the loop will, therefore, go on forever. 
    0

c plus plus programming
Practice Mock Test
c plus plus programming