What’s a null char?

Print anything with Printful



The null character, with a zero value, is used to indicate empty, undefined or uninitialized variables, classes or pointers. It was originally used to communicate with peripheral hardware and is now used to save memory space and initialize new variables.

A null character in computer programming is a character with a zero value. It is different from the number zero, which is part of the standard printed character set. Null is actually a control character with index zero. It is used to indicate that a variable, class or pointer is empty, undefined or uninitialized. A null is also used in the C programming language to mark the end of a string of characters.

The null character was originally one of a series of special control characters used to communicate with peripheral hardware such as printers or tape drives. The original meaning of null was to instruct a device to do nothing. As technology became more sophisticated, control characters were less needed for interfacing with external devices. The null remained in most character sets, however, at the zero position.

Many programming languages ​​use the null character to indicate that a value has not been assigned to a variable, pointer, or class. The value of null is often defined within the core programming language libraries as the value ‘/0’, which translates to a single blank character. A variable with a null value has no zero value. Zero is a completely different character code, so equivalence tests between zero and null will show a false result. This is by design, because zero can be a valid value for a variable.

The programming language known as C uses the null character to great effect to save memory space. The null character is used as the end of a character string, also called a null-terminated string. This allows the program to store a string with the need for only one more byte to contain the null terminator. The null character cannot be displayed and was not used for any other purpose, so this system worked fine.

Languages ​​after C have started using null to initialize new variables and classes. Most language specifications actually guarantee that newly declared variables will be null. Similarly, variables can be assigned the value null to indicate that they have no value or do not point to any memory location.

Some object-oriented languages ​​may use the null character during the garbage collection process. If a variable that contains an instance of a class is set to null, the data becomes unreachable unless otherwise indicated by another variable. The garbage collection mechanism, which frees previously used memory, detects unreachable data and returns it to the available memory pool. Explicitly assigning a variable to null is sometimes considered poor programming style.




Protect your devices with Threat Protection by NordVPN


Skip to content