I have this piece of code, but don't understand what this '\0' character is:
char[] str = new char[1];
str[0] = '\0';
Could someone explain it? If I print out the value of str[0] nothing is printed.
I have this piece of code, but don't understand what this '\0' character is:
char[] str = new char[1];
str[0] = '\0';
Could someone explain it? If I print out the value of str[0] nothing is printed.
That's the character with number 0 in the ASCII table. It's called NUL, doesn't have a visible(printable) representation and it's used for marking the end of a String.
Note that it's different than the null reference in Java.
More info:
It's the NUL character. Sometimes (in some languages) used to mark for example an end of a string of characters.
Character \0 is control character with ASCII code 0, which doesn't have printable representation, which explains why nothing is printed.