Dóra Takács wrote:
UPDATE:
So I checked if I add a println to the loop, and it actually seems like the supposed-to-be-infinite loop terminates after printing out a lot of 3s. So its actually the JVM that terminates the loop early, after (probably) detecting it doesnt do anything good. Now I feel even worse
Hint. What is the range of a byte? And what would happen when you add one to the maximum value?
And have you worked out why you only get one congratulatory message, rather than 127 of them?
And what about this code? Remember that a char is unsigned and doesn't support negative values.
Afraid that is incorrect. The right answer is in the Java® Language Specification.Rahul kumar verma wrote:Range of byte: -127 to 128
The loop will run 65536 × and on the last time, there will be overflow from 65535 (= 0xffff) returning c to 0, so you are right. If you had written c++ the initial value would have been 0, so the loop would never had started. Change the empty statement to something different, e.g.Dóra Takács wrote:. . . the loop ends eventually, right?
Being Java programmer.
No '\0' is not a space. You can look in the Unicode chart (ASCII/Basic Latin) to see what it really is. You are printing a space after the colon, then the command line cannot cope with most of the characters and prints ? A Linux terminal will print many more characters than a Windows® command line, which is notorious for the restricted range of characters available.Ganish Patil wrote:. . .I think initial value of h = '\0' is blank space because I tried to print that, it prints nothing. . . .
Opps! ,yes ASCII value of '0' char is 48 but it is 0 i.e. int whose ASCII value is 0030 given in you pdf link but I couldn't find what is '\0'Campbell Ritchie wrote:You wrote 0 not '0'
Oh I see, I was also thinking why it kept printing ? so many times.then the command line cannot cope with most of the characters and prints ?
Being Java programmer.
Thank you, is there any website where I can get the list of ASCII values. Where did you get that '\0' is NUL character. I used that in C language as end of string while doing string programs, where string is an array of character in C.Dave Tolls wrote:0 is 0.
It is the NUL character.
As is '\0'.
Being Java programmer.
Thank you once againDave Tolls wrote:It's the standard escape code for null:
https://en.wikipedia.org/wiki/Null_character#Representation
Being Java programmer.
Hundreds of websites, including the official Unicode site I posted a link to this morning.Ganish Patil wrote:. . . Thank you, is there any website where I can get the list of ASCII values. . . .
I was pleased to see they have ctrl‑shift‑P as a way to get a null character from the keyboard. I remember using ctrl‑shift‑P‑repeat to get blank paper tape out of a Teletype.Dave Tolls wrote:. . . https://en.wikipedia.org/wiki/Null_character#Representation
Consider Paul's rocket mass heater. |