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
239
votes
7 answers

MySQL CONCAT returns NULL if any field contain NULL

I have following data in my table "devices" affiliate_name affiliate_location model ip os_type os_version cs1 inter Dell 10.125.103.25 Linux Fedora cs2 inter …
Neeraj
  • 8,625
  • 18
  • 60
  • 89
235
votes
9 answers

How to set enum to null

I have an enum string name; public enum Color { Red, Green, Yellow } How to set it to NULL on load. name = ""; Color color = null; //error Edited: My bad, I didn't explain it properly. But all the answers related to nullable is perfect. My…
Sri Reddy
  • 6,832
  • 20
  • 70
  • 112
231
votes
10 answers

php is null when empty?

I have a question regarding NULL in PHP: $a = ''; if($a == NULL) { echo 'is null'; } Why do I see is null when $a is an empty string? Is that a bug?
Erin Tucker
  • 3,274
  • 2
  • 15
  • 22
229
votes
11 answers

Best explanation for languages without null

Every so often when programmers are complaining about null errors/exceptions someone asks what we do without null. I have some basic idea of the coolness of option types, but I don't have the knowledge or languages skill to best express it. What is…
214
votes
6 answers

nil detection in Go

I see a lot of code in Go to detect nil, like this: if err != nil { // handle the error } however, I have a struct like this: type Config struct { host string port float64 } and config is an instance of Config, when I do: if…
user1663023
212
votes
17 answers

How to use NULL or empty string in SQL

I would like to know how to use NULL and an empty string at the same time in a WHERE clause in SQL Server. I need to find records that have either null values or an empty string. Thanks.
poshan
  • 3,069
  • 5
  • 20
  • 30
208
votes
15 answers

getActivity() returns null in Fragment function

I have a fragment (F1) with a public method like this public void asd() { if (getActivity() == null) { Log.d("yes","it is null"); } } and yes when I call it (from the Activity), it is null... FragmentTransaction transaction1 =…
Lukap
  • 31,523
  • 64
  • 157
  • 244
206
votes
8 answers

Origin null is not allowed by Access-Control-Allow-Origin

I have made a small xslt file to create an html output called weather.xsl with code as follows:
dudledok
  • 2,800
  • 5
  • 24
  • 36
205
votes
21 answers

Do you use NULL or 0 (zero) for pointers in C++?

In the early days of C++ when it was bolted on top of C, you could not use NULL as it was defined as (void*)0. You could not assign NULL to any pointer other than void*, which made it kind of useless. Back in those days, it was accepted that you…
camh
  • 40,988
  • 13
  • 62
  • 70
203
votes
14 answers

Can I use if (pointer) instead of if (pointer != NULL)?

Is it safe to check a pointer to not being NULL by writing simply if(pointer) or do I have to use if(pointer != NULL)?
danijar
  • 32,406
  • 45
  • 166
  • 297
200
votes
14 answers

Checking for NULL pointer in C/C++

In a recent code review, a contributor is trying to enforce that all NULL checks on pointers be performed in the following manner: int * some_ptr; // ... if (some_ptr == NULL) { // Handle null-pointer error } else { // Proceed } instead…
Bryan Marble
  • 3,467
  • 5
  • 26
  • 29
195
votes
18 answers

How to simplify a null-safe compareTo() implementation?

I'm implementing compareTo() method for a simple class such as this (to be able to use Collections.sort() and other goodies offered by the Java platform): public class Metadata implements Comparable { private String name; private…
Jonik
  • 80,077
  • 70
  • 264
  • 372
195
votes
16 answers

Setting Objects to Null/Nothing after use in .NET

Should you set all the objects to null (Nothing in VB.NET) once you have finished with them? I understand that in .NET it is essential to dispose of any instances of objects that implement the IDisposable interface to release some resources…
John
  • 29,788
  • 18
  • 89
  • 130
193
votes
28 answers

How to check if my string is equal to null?

I want to perform some action ONLY IF my string has a meaningful value. So, I tried this. if (!myString.equals("")) { doSomething } and this if (!myString.equals(null)) { doSomething } and this if ( (!myString.equals("")) &&…
Roman
  • 124,451
  • 167
  • 349
  • 456
191
votes
5 answers

NULL vs nil in Objective-C

In observeValueForKeyPath:ofObject:change:context: - why do the docs use NULL instead of nil when not specifying a context pointer?
erikprice
  • 6,240
  • 3
  • 30
  • 40