Questions tagged [null]

Null means *nothing* or *unknown*, depending on context. Please use the "sql-null" tag for SQL specific questions.

"Null" has different meanings depending on context.

Set theory

Null is another name for the empty set, denoted by the symbol ∅. For this reason, some programming languages use null or nil for the empty list or empty tuple. Lisp uses nil to mean the empty list and the boolean value false.

Pointers and References

Null (or sometimes nil or None), in programming languages that support it, is the value of an uninitialized variable, a pointer that doesn't point to a meaningful memory address, or an object that fails to respond to any message.

Nullable references were invented by C.A.R. Hoare in 1965 as part of the Algol W language. Hoare later described his invention as a "billion-dollar mistake".

For more information, see Null pointer.

Agreeing with Hoare's sentiment, many languages don't have a special null value, choosing to use optional types instead.

Relational Databases

NULL as a special marker in SQL or a relational database stands in place of a value that is missing, or in a join means "no corresponding row." The operators IS NULL and IS NOT NULL are required for comparisons to a literal null: other comparisons between NULL and any value evaluate to "unknown."

For more information, see Null (SQL).

ASCII

Null or NUL is the name given to the character with ASCII code zero (0) - i.e. hex 00. In some languages, notably C, NUL is used to mark the end of a character string.

For more information, see Null character.

16208 questions
76
votes
8 answers

Standard use of 'Z' instead of NULL to represent missing data?

Outside of the argument of whether or not NULLs should ever be used: I am responsible for an existing database that uses NULL to mean "missing or never entered" data. It is different from empty string, which means "a user set this value, and they…
Boris Nikolaevich
  • 1,451
  • 11
  • 21
76
votes
9 answers

Any simple way to test null before convert an object to string

I always write Object o; if (o!=null) String s = o.toString(); If there simple way to handle this case?
user496949
  • 83,087
  • 147
  • 309
  • 426
76
votes
3 answers

Portably safe to pass NULL/zero to dynamic_cast?

Out of habit for checking null pointers, I have sometimes written: MyClass * c = someBasePtr ? dynamic_cast(someBasePtr) : 0; if (c) {... In effect, checking for a null pointer before passing to dynamic cast, and also checking the…
sdg
  • 4,645
  • 3
  • 32
  • 26
76
votes
4 answers

Prevent unlist to drop NULL values

I have a vector of lists and I use unlist on them. Some of the elements in the vectors are NULL and unlist seems to be dropping them. How can I prevent this? Here's a simple (non) working example showing this unwanted feature of unlist a =…
nico
  • 50,859
  • 17
  • 87
  • 112
76
votes
25 answers

Why is "null" present in C# and Java?

We noticed that lots of bugs in our software developed in C# (or Java) cause a NullReferenceException. Is there a reason why "null" has even been included in the language? After all, if there were no "null", I would have no bug, right? In other…
sthiers
  • 3,489
  • 5
  • 34
  • 47
75
votes
10 answers

Entity Framework : Value cannot be null. Parameter name: type

When I execute update-database command, it shows this error message System.ArgumentNullException: Value cannot be null. Parameter name: type at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args,…
Nahro Fuad
  • 751
  • 1
  • 5
  • 5
75
votes
3 answers

What's the point of Guava checkNotNull

I'm pretty new to Guava (let's be honest, I'm not "pretty new", I'm a complete rookie on that subject) and so I decided to go through some documentation and got quite amazed while reading…
Ar3s
  • 2,237
  • 2
  • 25
  • 47
75
votes
3 answers

Define a variable and set it to a default value if something goes wrong during definition

I have the following code in my build.gradle Contents in version.properties are: buildVersion=1.2.3 Value of $v variable during the Gradle build is coming as: 1.2.3 Value of $artifactoryVersion variable in JENKINS build is coming as: 1.2.3.1,…
AKS
  • 16,482
  • 43
  • 166
  • 258
74
votes
5 answers

Is NULL always zero in C?

I was interviewing a guy for a mid-level software engineering position yesterday, and he mentioned that in C, NULL is not always zero and that he had seen implementations of C where NULL is not zero. I find this highly suspect, but I want to be…
chi42
  • 925
  • 1
  • 7
  • 8
74
votes
7 answers

How to convert empty spaces into null values, using SQL Server?

I have a table and the columns on this table contains empty spaces for some records. Now I need to move the data to another table and replace the empty spaces with a NULL value. I tried to use: REPLACE(ltrim(rtrim(col1)),' ',NULL) but it doesn't…
niceApp
  • 2,913
  • 8
  • 35
  • 36
74
votes
7 answers

obj.nil? vs. obj == nil

Is it better to use obj.nil? or obj == nil and what are the benefits of both?
Danish Khan
  • 1,230
  • 1
  • 10
  • 13
74
votes
2 answers

What is the PHP syntax to check "is not null" or an empty string?

Possible Duplicate: Check if a variable is empty Simple PHP question: I have this stement: if (isset($_POST["password"]) && ($_POST["password"]=="$password")) { ...//IF PASSWORD IS CORRECT STUFF WILL HAPPEN HERE } Somewhere above this statement…
I wrestled a bear once.
  • 22,983
  • 19
  • 69
  • 116
73
votes
2 answers

Using COALESCE to handle NULL values in PostgreSQL

I have the following query SELECT DISTINCT pt.incentive_marketing, pt.incentive_channel, pt.incentive_advertising FROM test.pricing pt WHERE pt.contract_id = 90000 group by 1,2,3 order by pt.incentive_marketing; The above…
ronan
  • 4,492
  • 13
  • 47
  • 67
73
votes
14 answers

How do I return my records grouped by NULL and NOT NULL?

I have a table that has a processed_timestamp column -- if a record has been processed then that field contains the datetime it was processed, otherwise it is null. I want to write a query that returns two rows: NULL xx -- count of records…
Stewart Johnson
  • 14,281
  • 7
  • 61
  • 70
73
votes
7 answers

Best way to check if a character array is empty

Which is the most reliable way to check if a character array is empty? char text[50]; if(strlen(text) == 0) {} or if(text[0] == '\0') {} or do i need to do memset(text, 0, sizeof(text)); if(strlen(text) == 0) {} Whats the most efficient way…
ZPS
  • 1,566
  • 4
  • 16
  • 20