What does this code: (especially, what does a backslash '\' ? )
s23_foo += \
s8_foo * s16_bar;
I added the datatypes, because they might be relevant. Thanks for your help.
In Windows systems, for example, the backslash is used to separate elements of a file path, for example: C:\Documents\User\File. In C, Perl and Unix scripting, the backslash indicates that the following character must be treated in some special way. Within the TeX typesetting markup system, the backslash starts tags.
It is an ascii character and can be used anywhere. \a Is used to display a sound.
\0 is zero character. In C it is mostly used to indicate the termination of a character string. Of course it is a regular character and may be used as such but this is rarely the case. The simpler versions of the built-in string manipulation functions in C require that your string is null-terminated(or ends with \0 ).
It is a “backwards slash” that is the reverse of a forward slash ( / ). The backslash has no usage in formal or informal writing. It is not considered to be a punctuation mark and shouldn't be confused with the forward slash (often just called a slash), which is used as a punctuation mark in writing.
What are Backslash character constants in C language? A backslash ( \ ) that allows a visual representation of some nongraphic characters introduces an escape. One of the common escape constants is the newline character ( ).
A backslash ( \ ) that allows a visual representation of some nongraphic characters introduces an escape. One of the common escape constants is the newline character ( ). The backslash characters are as follows −
Each instance of a backslash character (\) immediately followed by a new-line character is deleted, splicing physical source lines to form logical source lines. Only the last backslash on any physical source line shall be eligible for being part of such a splice.
In C ,Backslash (\) is a escape sequence character followed by predefined alphabets ( E.g - \t, \b, \r, \n…etc.). It indicate that the character to their right should be interpreted differently. Its a non-printable characters, if you want to print (\) , you’ve to use (\\) . And Slash (/) is a normal character.
Backslashes denote two different things in C++, depending on the context.
Outside of a quotes string (see below), a \
is used as a line continuation character. The newline that follows at the end of the line (not visible) is effectively ignored by the preprocessor and the following line is appended to the current line.
So:
s23_foo += \
s8_foo * s16_bar;
Is parsed as:
s23_foo += s8_foo * s16_bar;
Line continuations can be strung together. This:
s23_foo += \
s8_foo * \
s16_bar;
Becomes this:
s23_foo += s8_foo * s16_bar;
In C++ whitespace is irrelevant in most contexts, so in this particular example the line continuation is not needed. This should compile just fine:
s23_foo +=
s8_foo * s16_bar;
And in fact can be useful to help paginate the code when you have a long sequence of terms.
Since the preprocessor processed a #define
until a newline is reached, line continuations are most useful in macro definitions. For example:
#define FOO() \
s23_foo += \
s8_foo * s16_bar;
Without the line continuation character, FOO
would be empty here.
Within a quotes string, a backslash is used as a delimiter to begin a 2-character escape sequence. For example:
"hello\n"
In this string literal, the \
begins an escape sequence, with the escape code being n
. \n
results in a newline character being embedded in the string. This of course means if you want a string to include the \
character, you have to escape that as well:
"hello\\there"
results in the string as viewed on the screen:
hello\there
The various escape sequences are documented here.
It lets you continue a statement onto the next line - typically you only need it inside a #define macro block
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With