What does NULL actually mean?

43

Many people talk about what is NULL, but after all, what is its true meaning?

    
asked by anonymous 02.10.2015 / 18:46

6 answers

41
  

The question was edited when there were already several answers, including the one that was best suited to the initial scope of the question. It's still valid, but I need to put this in for those who do not understand why I'm talking about Java and C ++.

null in Java, or NULL (in C and C ++ in the old style) or nullptr (modern C ++) is the indetermination of a value. In the context of the question it is always represented by a pointer being 0, that is, by pointing to an address that was conventionally invalid in memory. So the code knows it can not access anything.

In this context, the null has a value, as indicated above. But it does not point to a valid object that should have significant value for the type it represents. It indicates that there is no corresponding object for that value.

Null is not a type in these languages. Nor does it mean absence of type. It may be one type in others.

null == null and is different from all the rest (in these languages).

Obviously trying to access something in the object that should exist in a variable with null value will produce an error, since there is nothing there to access.

In other contexts, it may have a more specific and slightly different definition.

In SQL, for example, only indicates the value indetermination. There is nothing of this memory thing, another object. Some mistakenly say that it is nothing, or lack of value, but this is not correct. There are cases where people use the null to give some specific semantics and say it is "not applicable", "non-existent", "not defined", or something like that. But this is something specific to the application.

Null can be just the string terminator in the C pattern (the most used string pattern). It is used because it is an invalid character in any text.

Other "millions" of definitions can be found here .

Use in other contexts .

It's called " the trillion dollar error (ok, I've updated the values, the original speaks in billion)

Null is not the same as Null Object .

Auxiliary Reading: What is the difference between pointer and reference?

    
02.10.2015 / 18:58
59

Legend has it that in a far-flung province there was a monastery where Master Programmer shared his teachings. One of his dialogues was about NULL.

' Master ' asked Wu junior court analyst, ' What does NULL ? '

' You ask me about the indecipherable ' replied Master Programmer. ' NULL is what never was, and never will be.'

'It's your reflection on a lake that never existed. The child who was never conceived.
The love he never called his own, because he lacked courage. It's the dark of the world, and beyond. '

'Is this the object I've never saved?'

'No. This object was destroyed by Garbage Collector , after being Disposed(); . '

'Is the variable that I declare but never initialized?'

'No. In the uninitialized variable there is the potential for grandiosity; his future is not yet written, and may not even exist - but his place is reserved in the history of the world. It is undefined , or uninitialized . '

'And why do so many languages implement NULL ?'

'Because we must admit our ignorance. What we do not know, can not be described; what has no value can not be evaluated. '

'So why not use zero, or a space?'

'You want a zero because your mind can not abandon the concept of something . It associates zero, a numerical absence, to nothingness - and even nothingness is more than NULL . Your code will then carry an entropy seed. It will be separate from Zen , and on its way to become spaguetti > . '

'But, Master ... so why in PHP, (array() == null); ?'

The Master Programmer then sighed. This would be a long afternoon.

    
02.10.2015 / 19:21
10

On the Macoratti site, it defines NULL as follows:

  

Null   A value that indicates missing or unknown data in a field. You can use Null values in expressions. Null values can be entered into fields from which information is unknown, as well as   such as expressions and queries.

In my conception it is a type of data that is not empty and is not zero, for me it is unfilled information, or rather, not defined.

    
02.10.2015 / 18:52
7

Null is basically no value.

Ex:

public $variavel = 0; //não é nulo!

public $variavel; // é nulo
    
02.10.2015 / 18:51
5

NULL means null, no value. Imagine, for example, an optional balance property accepting any real numbers. Being optional there is no number to be assigned that indicates that there is no balance assigned, because 0, positive values and negative values are valid balance values. Assigning NULL indicates no value assigned. It is simply a representation of no value .

    
02.10.2015 / 18:54
3
  

NULL , NIHIL, N / C - all this means null, unanswered, blank.

     

The special value NULL means that the variable has no value. NULL is the only possible value of type NULL .

     

Null is the ASCII character "00", it is the value of a variable that has not yet been initialized

    
02.10.2015 / 18:49