+ 2
Can u plz explain how's the output '-128' A challenge Q&A of sololearn quiz
The question posted was as follows byte by=1; while(by>0) b++; System.out.print(by); The right output given was '-128' Can u plz explain the logic behind it.
6 Answers
+ 6
Every number type has a limit to what it can hold.
A byte can hold the numbers from -128 to 127.
So if you add 1, after a while the byte 'overflows'.
Then it starts over from the bottom end and now is < 0.
+ 3
HonFu thanks bro Had similar thoughts but wanna verified.
+ 2
Dint get u?
+ 2
while(by>0) {
++by;
printf("%d", by);
}
Like this, you can examine what happens.
+ 1
A good way to verify that sort of thing (also to debug short codes):
Rewrite the code, but output the values!
That way you can exactly follow what happens step by step.
- 1
HonFu u were too in pythonist grp right?
Hot today
Please help, any idea?
2 Votes
Loop question, I've tried everything that I knew I just don't know. Please help me solve it out
1 Votes
What is wrong? Error on test.
1 Votes
Help me solve this (using loop)
1 Votes
Help me wiht python
1 Votes
how can i flip any word with c++
0 Votes