0

How many times will the following loop run?

for(char c=0; c<266; ++c) {}

31st Aug 2018, 10:19 PM
M.Saariya Faiz
M.Saariya Faiz - avatar
3 Respostas
+ 2
Infinitely. ASCII table has 128 characters (they hold values between 0 and 127). Maximum value (127) + 1 gives a minimum value, so 266 won't be reached.
31st Aug 2018, 11:28 PM
Steppenwolf
Steppenwolf - avatar
+ 2
it is an infinite loop this is known as overflow of signed char check this for more infos: https://www.geeksforgeeks.org/what-happens-if-loop-runs-till-maximum-of-signed-and-unsigned-in-c/
31st Aug 2018, 11:22 PM
MO ELomari
MO ELomari - avatar
+ 2
sorry, ignore my previous answer. i didn't pay close attention and didn't see that it wasn't an int.
1st Sep 2018, 1:06 AM
J.G.
J.G. - avatar