Output of C++ code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Output of C++ code

Can someone explain the output of this code? https://code.sololearn.com/cpokwoCQR1Zv/#cpp

26th Sep 2020, 9:00 PM
Edward Finkelstein
Edward Finkelstein - avatar
3 Answers
+ 2
`char` data range spans from -128 up to 127, when `++c` is executed, <c> value wraps to -128 which is less than 128 (loop condition), so basically, the loop is infinite because the limit is never reached.
26th Sep 2020, 9:14 PM
Ipang
+ 3
Out of range. Last number of char in ASCII table is 127, but ++c in your loop make char c = 128 so it is out of type's range. When you condition is c < 127 it make last value of c = 127.
26th Sep 2020, 9:14 PM
Derlas Forenly
Derlas Forenly - avatar
+ 2
@Ipang Yeah, so I do something like this for (char c=0; c<128; ++c){cout << (int) c << endl;} and I see what you describe, strange, but true. Thank you Thank you @Derlas Forenly
26th Sep 2020, 9:54 PM
Edward Finkelstein
Edward Finkelstein - avatar