user3901918
user3901918

Reputation:

Why is there a need for the escape character '\'' in C?

Im just curious why there is a need to escape a single quote character when you could actually print a single quote in the printf function without having the need to escape it.

Upvotes: 0

Views: 167

Answers (3)

glglgl
glglgl

Reputation: 91049

If you want to embed a " in a string or have a character like ', you need to escape.

You can workaround this if you only intend to use printf(), but for general use, you might want to need both.

For example, you might want to send the string I said "hello" via a socket connection, or write it into a file, then you'd have to make ugly hacks because you are restricted if you couldn't do so.

Upvotes: 1

HaMi
HaMi

Reputation: 539

Suppose you want to compare a character value with single quote. In this case you need something like if(c == '\'').

Upvotes: 0

mcleod_ideafix
mcleod_ideafix

Reputation: 11428

To allow for character initializations like this:

char quote = '\'';

Upvotes: 4

Related Questions