For the code:
#include <stdio.h>
int main(void) {
\
printf("Test");
}
compiling via gcc -Wall -Wextra -Wfatal-errors test.c
gives no warnings.
However for other stray characters, compiling leads to the following error:
test.c:3:1: error: stray ‘`’ in program
`
^
compilation terminated due to -Wfatal-errors.
I tried the same, with different stray characters, and each time I got an error.These errors ranged from expected primary-expression before the token
to value computed is not used
. I was expecting a similar warning/error for the backslash character as well.
So, does a stray backslash followed by no spaces have no meaning in C code?
I know for a fact that redundant semicolons (;) have no effect in C code, so are these somehow related?
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.
\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 ).
Go to the line which is reported and you see the straying special char. That happens if you had opend or edited you sourcecode with an editor that enters “non breakable spaces” instead of the common whitespace. That might happen if you push “shift-space” instead of only “space”, depending on the editor you use.
C++ comments come in two flavors: single-line comments and multiline comments. Single-line comments are accomplished using a double slash (//). The double slash tells the compiler to ignore everything that follows, until the end of the line.
error: stray '\' in program. If you are getting error messages like above in your C/C++ program, then don't worry. ;-) Perhaps you have copied the code from somewhere. If your code is small ,then the simplest solution is that you should start typing it from zero.
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 ( ).
The reason for this is that your code might contain some hidden octal (not-readable) characters which the compiler cant understand and you can not see. They are present in your code because you have perhaps copied it from somewhere. So, simply you can retype the same code to solve the problem.
But, after you’ve played through the adventure, you might want the somewhat abrupt Stray ending explained. Stray presents many questions as you play through the game, but because you’re a cat and can’t talk in human (only meows), it’s hard for any exposition to be delivered, especially towards the end of the game.
The backslash is escaping the newline that follows it. It is used to logically combine two or more lines in cases where whitespace is relevant, such as in the middle of a string constant or as part of a macro definition so that it may span multiple lines.
In this particular case the whitespace is not significant so there is no effect on the code.
If you were to add spaces after the \
you would get a warning, and if you put a ;
after those spaces you would get an error regarding a stray \
.
It's the line continuation character. (You see it most often in macros.) The trigraph ??/
has the same effect.
If there was whitespace after it, then a compiler would issue a diagnostic.
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