NULL means that memory has not been allocated to the pointer (string). So there is no representation of the string in memory.
On the other hand, a string can be initialised as “” (empty string). This does mean that memory is allocated, and it is present in memory, it’s just empty. That means its length is 0.
In most commonly-used programming languages, strings are represented via reference types. That means a variable like ‘s’ contains a reference to the data, rather than the data itself, and the reference might be null (not referring to anything). It also means that you can have multiple variables that are aliased, meaning changes to the data will immediately be visible to all those references.
In Java, for example, fields of reference type are initialized to null.
In some languages, if you try to call a method like length() on a variable that is set to null, you’ll crash the program. So a common tactic is to rule that out with a short-circuit Boolean operator like ||.
When I give interviews, I want the candidate to at least understand the ramifications of null references getting involved, but I’m not looking for answers to always handle that case. Many common library methods take the position that you get what you deserve (an exception) if you try to pass them a null parameter.
多浏览英文网站,多看别人的response,英语很重要,很多答案和解释比较贴切