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
7
votes
1 answer

Testing for null, inline, on an ASP.net Bind() call

I've got a bit of code that I started to manage, and it's begun to fail due to some data missing in the database. This case could happen in the future, so I'd like to gracefully handle the nulls in the front end. Here's the current…
Carl
  • 1,706
  • 1
  • 17
  • 25
7
votes
2 answers

Checking for nil Value in Swift Dictionary Extension

I have the following code in a playground file: extension Dictionary { func test() { for key in self.keys { self[key] } } } var dict: [String: AnyObject?] = [ "test": nil ] dict.test() I will henceforth…
Alex311
  • 378
  • 3
  • 12
7
votes
1 answer

How to check a 2D matrix is empty?

I think that all we need is if (matrix.length == 0) However, I saw some of them write if (matrix == null || matrix.length == 0 || matrix[0].length == 0) Is my version enough to check a matrix is empty or not or we need to write the above…
KKKK
  • 347
  • 7
  • 18
7
votes
2 answers

How do you create a class that does not inherit from Object.prototype using ES6 classes?

I can create a class that does not inherit from Object.prototype using the older syntax. function Shape(x, y, width, height) { this.x = x, this.y = y, this.width = width, this.height = height; } Shape.prototype =…
Michael Theriot
  • 994
  • 7
  • 13
7
votes
6 answers

What if a null character is present in the middle of a string?

I understand that the end of a string is indicated by a null character, but i cannot understand the output of the following code. #include #include int main(void) { char s[] = "Hello\0Hi"; printf("%d %d", strlen(s),…
Ranjan Srinivas
  • 347
  • 1
  • 3
  • 10
7
votes
4 answers

Why can't my Java method change a passed variable?

I was kind of baffled when I saw the following code did not work as expected. I thought Java always passed variables by references into functions. Therefore, why can't the function reassign the variable? public static void main(String[] args) { …
Will
  • 1,622
  • 4
  • 25
  • 39
7
votes
1 answer

App crashes when run from phone but works fine when launched from computer

I've been able after 3 days of work to make an old app run on my device! But only when the command comes from my computer... I explain. When I launch the app from Android Studio on my phone, it launches fine, which is great. But when I launch it…
dequec64
  • 923
  • 1
  • 8
  • 26
7
votes
3 answers

Calling instance method on a null reference in IL

Is it correct that a instance method can be called on a null reference in IL..? Is there any example to show this..?
Santhosh
  • 6,547
  • 15
  • 56
  • 63
7
votes
2 answers

SQL plan compilation and truth tables

If I have NOT ( 1 <> 1 AND NULL <> 1 ) I can see SQL turning this into in the execution plan XML: ( 1 = 1 OR NULL = 1) If you would literally evaluate the former expression, the True AND Null would be Null and would eliminate the row. However, the…
J.T.
  • 2,606
  • 15
  • 31
7
votes
3 answers

Should null be checked on the left or right hand side

In reviewing some code, I have seen: if (null == condition) { ... } and I've also seen: if (condition == null) { ... } I seem to remember that there's an advantage to having null on the left hand side, but I can't remember it and was thinking that…
David Hoerster
  • 28,421
  • 8
  • 67
  • 102
7
votes
7 answers

C++ string that can be NULL

I'm used to passing around string like this in my C++ applications: void foo(const std::string& input) { std::cout << input.size() << std::endl; } void bar() { foo("stackoverflow"); } Now I have a case where I want the string to be NULL: void…
activout.se
  • 6,058
  • 4
  • 27
  • 37
7
votes
6 answers

Difference between an empty ArrayList and an ArrayList with null elements?

I am coding some validators for a REST service which parse a JSON and I found out something that sounds wierd for me (I am not a JAVA expert at all). Consider having two ArrayLists: ArrayList list1 = new…
melli-182
  • 1,216
  • 3
  • 16
  • 29
7
votes
1 answer

Groovy: getClass method on map literal returns null

In Groovy I use the map literal notation quite frequently in my code, and was curious as to what concrete implementation of Map it was. After trying a few things, this script best illustrates my confusion: def map = ["A":"B"] println map // I assume…
Kirie
  • 93
  • 6
7
votes
3 answers

null value in column "last_login" violates not-null constraint

Having issues getting rid of this error. I'm trying to use Digital Ocean to deploy my Django app. I configured Postgres, but when I'm trying to register a new user in my app, I get this problem. I've tried running python manage.py makemigrations…
noobprogrammer
  • 345
  • 1
  • 6
  • 20
7
votes
1 answer

Clean way to read a null-terminated (C-style) string from a file?

I'm looking for a clean and simple way to read a null-terminated C string from a file or file-like object in Python. In a way that doesn't consume more input from the file than it needs, or pushes it back onto whatever file/buffer it works with such…
Craig Ringer
  • 307,061
  • 76
  • 688
  • 778