1

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.

jcm
  • 5,499
  • 11
  • 49
  • 78

3 Answers3

2

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:

Konstantin Yovkov
  • 62,134
  • 8
  • 100
  • 147
2

It's the NUL character. Sometimes (in some languages) used to mark for example an end of a string of characters.

Kayaman
  • 72,141
  • 5
  • 83
  • 121
0

Character \0 is control character with ASCII code 0, which doesn't have printable representation, which explains why nothing is printed.