Jump to content

c programing


anmol6161

Recommended Posts

Because each "\\" prints one "\". The reason is that you need what I believe is called an escape character, which is a character indicating a "command" rather than a normal letter. By "command", I mean an output that you cannot properly represent in your source code editor. For example, a carriage return is "\n" (go ahead and printf "this\nis\nan\nexample\nwith\nmultiple\nlines" to test it). The problem is that if you want to print the actual escape character on screen you cannot simply write this character, because the language would expect it to indicate a following "command". The solution is to make printing of the escape character a "command", too. So the command for a new line is "\n", and the command for a backslash is "\\".

This is, by the way not unique to C. If you ever use latex (e.g. for mathematical formulas in this forum) you may encounter the same concept, there.

Edited by timo
Link to comment
Share on other sites

\ in ASCII is used to represent a special character, since C\C++ have ASCII as their default character-encoding

 

We've \n (new line) \r (line break:win) \t (vertical tab) ...

 

And to represent \ in output, it's considered as a special character .. so we write \\ which represent a single \

 

take this example, and check what happens:

 

void main ()
{
       printf ( "hidden\b\b\b\b\b\b" );
}

 

you will see nothing printed, but actually .. the console first print the characters: h, i, d, d, e, n .. then every

special character \b (backspace) removes a single character

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.