Backslash
Backslash
Main page

Backslash

logo
Community Hub0 subscribers
What are your thoughts?
Be the first to start a discussion here.
Be the first to start a discussion here.
Backslash

The backslash \ is a mark used mainly in computing and mathematics. It is the mirror image of the common slash ('solidus'), /. It is a relatively recent mark, first documented in the 1930s. It is sometimes called a hack, whack, escape (from C/UNIX), reverse slash, slosh, backslant, backwhack, bash, reverse slant, reverse solidus, and reversed virgule.

As of November 2022, efforts to identify either the origin of this character or its purpose before the 1960s have not been successful. The earliest known reference found to date is a 1937 maintenance manual from the Teletype Corporation with a photograph showing the keyboard of its Kleinschmidt keyboard perforator WPE-3 using the Wheatstone system. The symbol was called the "diagonal key", and given a (non-standard) Morse code of  ▄ ▄▄▄ ▄ ▄ ▄▄▄ .

In June 1960, IBM published an "Extended character set standard" that includes the symbol at 0x19. In September 1961, Bob Bemer (IBM) proposed to the X3.2 standards committee that [, ] and \ be made part of the proposed standard, describing the backslash as a "reverse division operator" and cited its prior use by Teletype in telecommunications. In particular, he said, the \ was needed so that the ALGOL Boolean operators (logical conjunction) and (logical disjunction) could be composed using /\ and \/ respectively. The Committee adopted these changes into the draft American Standard (subsequently called ASCII) at its November 1961 meeting.

These operators were used for min and max in early versions of the C programming language supplied with Unix V6 and V7.

In many programming languages such as C, Perl, PHP, Python and Unix scripting languages, and in many file formats such as JSON, the backslash is used as an escape character, to indicate that the character following it should be treated specially (if it would otherwise be treated literally), or literally (if it would otherwise be treated specially). For instance, inside a C string literal the sequence \n produces a newline byte instead of an 'n', and the sequence \" produces an actual double quote rather than the special meaning of the double quote ending the string. An actual backslash is produced by a double backslash \\.

Regular expression languages used it the same way, changing subsequent literal characters into metacharacters and vice versa. For instance \||b searches for either '|' or 'b', the first bar is escaped and searched for, the second is not escaped and acts as an "or".

Outside quoted strings, the only common use of backslash is to ignore ("escape") a newline immediately after it. In this context it may be called a "continued line" as the current line continues into the next one. Some software replaces the backslash+newline with a space.

To support computers that lacked the backslash character, the C trigraph ??/ was added, which is equivalent to a backslash. Since this can escape the next character, which may itself be a ?, the primary modern use may be for code obfuscation. Support for trigraphs in C++ was removed in C++17, and support for them in C was removed in C23.

See all
User Avatar
No comments yet.