How 04 is a character in this without single quotes | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6

How 04 is a character in this without single quotes

Java https://code.sololearn.com/c4vNkR8nP2dh/?ref=app

14th May 2021, 2:22 PM
alagammai uma
alagammai uma - avatar
10 Answers
+ 1
a character literal is nothing more than a UTF-16 encoded integer. instead of using the literal character you are directly assigning the corresponding numeric encoding
14th May 2021, 2:43 PM
Ciro Pellegrino
Ciro Pellegrino - avatar
+ 6
How is 04 a character when it has no single quotes? char accepts either a character with single quotes or a direct ASCII value. Any value leading with 0 is octal number(base 0-7) eg: 04, 065 etc char f = 04; // if we convert octal number 04 to decimal value we will have 4 // Now f = 4 and if you check from the ascii value number 4 is use for "end of transmission" sign and hence we empty blank output. One more example: Suppose you have, char f = 065; 065 is octal and is converted to decimal by compiler and hence we have 53(decimal), again check in the ascii table you will find that the value 53 is '5' and hence we will get an output of 5.
14th May 2021, 2:36 PM
Rohit
+ 2
rkk Thanks
14th May 2021, 2:44 PM
Kalaiselvan
Kalaiselvan - avatar
+ 2
rkk what I am getting error on inputing 08?
14th May 2021, 2:50 PM
Atul [Inactive]
+ 2
Atul because octal is base (0-7) so 8 is not in its range
14th May 2021, 2:50 PM
Rohit
+ 1
Ciro Pellegrino can u please elaborate ur explanation?
14th May 2021, 2:32 PM
alagammai uma
alagammai uma - avatar
+ 1
rkk Do 04 is the only numbers for the end of transmission or the numbers from 0-7?
14th May 2021, 3:10 PM
Atul [Inactive]
+ 1
Atul octal 04 when converted to decimal is 4 and if you check in ascii values table you will see that 4 is used for "end of transmission" and that this is the reason we are getting an empty output. Yes, there's only one number 4 for "end of transmission". I think you are asking this question because for some other values too you will get an empty output and that's because some weird ascii value will print empty blank output. Check this ascii value table for: https://images.app.goo.gl/NjUAm1jRpuWLvfcM9
14th May 2021, 3:15 PM
Rohit
14th May 2021, 3:01 PM
alagammai uma
alagammai uma - avatar
0
rkk thank you
14th May 2021, 3:03 PM
alagammai uma
alagammai uma - avatar