Null Character

The null character (also null terminator) is a control character with the value zero.

It is present in many character sets, including those defined by the Baudot and ITA2 codes, ISO/IEC 646 (or ASCII), the C0 control code, the Universal Coded Character Set (or Unicode), and EBCDIC. It is available in nearly all mainstream programming languages. It is often abbreviated as NUL (or NULL, though in some contexts that term is used for the null pointer). In 8-bit codes, it is known as a null byte.

The original meaning of this character was like NOP—when sent to a printer or a terminal, it has no effect (some terminals, however, incorrectly display it as space). When electromechanical teleprinters were used as computer output devices, one or more null characters were sent at the end of each printed line to allow time for the mechanism to return to the first printing position on the next line.[citation needed] On punched tape, the character is represented with no holes at all, so a new unpunched tape is initially filled with null characters, and often text could be inserted at a reserved space of null characters by punching the new characters into the tape over the nulls.

Today the character has much more significance in the programming language C and its derivatives and in many data formats, where it serves as a reserved character used to signify the end of a string, often called a null-terminated string. This allows the string to be any length with only the overhead of one byte; the alternative of storing a count requires either a string length limit of 255 or an overhead of more than one byte (there are other advantages/disadvantages described in the null-terminated string article).

Representation

In source code, the null character is often represented as the escape sequence \0 in string literals (for example, "abc\0def") or in character constants ('\0'); the latter may also be written instead simply as 0 (without quotes nor slash). In many languages (such as C, which introduced this notation), this is not a separate escape sequence, but an octal escape sequence with a single octal digit 0; as a consequence, \0 must not be followed by any of the digits 0 through 7; otherwise it is interpreted as the start of a longer octal escape sequence. Other escape sequences that are found in use in various languages are \000, \x00, \z, or \u0000. A null character can be placed in a URL with the percent code %00.

The ability to represent a null character does not always mean the resulting string will be correctly interpreted, as many programs will consider the null to be the end of the string. Thus the ability to type it (in case of unchecked user input) creates a vulnerability known as null byte injection and can lead to security exploits.

In caret notation the null character is ^@. On some keyboards, one can enter a null character by holding down Ctrl and pressing @ (on US layouts just Ctrl+2 will often work, there being no need for ⇧ Shift to get the @ sign).

The Hexadecimal notation for null is 00. Decoding the Base64 string AA== also yields the null character.

In documentation, the null character is sometimes represented as a single-em-width symbol containing the letters "NUL". In Unicode, there is a character for this: U+2400 SYMBOL FOR NULL.

Encoding

In all modern character sets, the null character has a code point value of zero. In most encodings, this is translated to a single code unit with a zero value. For instance, in UTF-8 it is a single zero byte. However, in Modified UTF-8 the null character is encoded as two bytes: 0xC0,0x80. This allows the byte with the value of zero, which is now not used for any character, to be used as a string terminator.

References

Tags:

Null Character RepresentationNull Character EncodingNull CharacterASCIIBaudot codeC0 and C1 control codesCharacter setControl characterEBCDICISO/IEC 646ITA2Null pointerProgramming languageUnicodeUniversal Coded Character Set

🔥 Trending searches on Wiki English:

You Should Have LeftJustin BieberSherri MartelSeppukuXNXXAbdul FatawuGrey's AnatomyCillian MurphySnapchatNo Way UpICC Men's T20 World CupUkraineZoë KravitzKim Soo-hyunPoodle skirtEva MendesList of highest-grossing Malayalam filmsJohnny BallSexual intercourseMaya RudolphVasuki indicusAlia BhattRalf RangnickAmy SchumerCatherine, Princess of WalesJames VI and IGeorge SorosThe World's BillionairesCat2024 Indian general election in Uttar PradeshSandra DeeTom CruiseInter MilanAssassination of William McKinleyMax VerstappenNicholas GalitzineHozierKysre GondrezickEFL ChampionshipNicole KidmanCrystal Palace F.C.Orpheus PledgerClara BowBaby ReindeerRichard GaddAnti-Hero (song)Bruno FernandesJohn Quincy AdamsCleopatraEarthAnne HecheGoogle MapsKent State shootingsThe Beekeeper (2024 film)Karen McDougalPlanet of the ApesSt. Vincent (musician)Kannauj Lok Sabha constituencyArsenal F.C.Black Sails (TV series)Alex GarlandSofía VergaraList of Marvel Cinematic Universe filmsJarrad BranthwaiteCaitlin ClarkCameron GrimesPassover SederUnited NationsBrazilSingaporeSouth AfricaSeverance (TV series)2024 Indian general election in Tamil NaduChris BrownDonte DiVincenzoLockheed Martin F-35 Lightning IICrackhead BarneyOda Nobunaga🡆 More