0
Can someone explain me what null keyword does?
I serched for information on google but didn't find any good explanation.
6 Respuestas
+ 5
What language?
In SQL, for instance, it's a flag to tell that a field has no value.
In C and C++, the NULL macro is equivalent to 0.
+ 3
You can test it out for yourself:
class Test {}
public class Program
{
public static void main(String[] args) {
Test one = null;
Test two = new Test();
System.out.println(one);
System.out.println(two);
}
}
+ 2
For C# and Java, null refers to a null reference, the default value of all reference type. Objects which are null, cannot be used to invoke class methods (exceptions will be thrown).
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/null
https://stackoverflow.com/questions/2707322/what-is-null-in-java
Quoting Roman Cherepanov in the above article
- "null is used to denote non-existence of an object".
0
C# / Java
0
Good explanation! Thanks alot!
0
Another way to see it would be that NULL is a value that indicates the variable has no useful value assigned yet.
You can see it similar to \0, which indicates the end of a string in C and C++, or ony othe control character, which are also values that indicate things