Q:

Error: Invalid escape sequence in C | Common C program Errors

belongs to collection: C Common Errors Programs

0

Error: Invalid escape sequence in C | Common C program Errors

Sometimes, while writing Escape Sequences in C program, we mistakenly typed an invalid escape sequence, which does not give any error but does not give the expected result.

For example, if we want to print a "new line" between two words in a text and mistakenly typed \m instead of \n.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Consider the program:

#include <stdio.h>

int main(void) {
	
	printf("Hello world\mHow are you?");
	
	return 0;
}

Output

    Hello worldmHow are you?

We wanted to print "Hello world" and "How are you?" in separate lines but there is an invalid escape sequence \m. Thus, the result is "Hello worldmHow are you?".

How to fix "Invalid escape sequence in C" error

To fix this and such errors, you should know about all escape sequences and use them properly.

Read: Escape sequences in C

Correct code

#include <stdio.h>

int main(void) {
	
	printf("Hello world\nHow are you?");
	
	return 0;
}

Output

    Hello world
    How are you?

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Error: Unterminated comment (Invalid comment block... >>
<< Fatal Error: stio.h: No such file or directory in ...