anmol6161 Posted November 13, 2011 Posted November 13, 2011 sir, void main() { printf("\\\\\\\\"); getch(); } output is only \\\\ slash why???????????????
timo Posted November 13, 2011 Posted November 13, 2011 (edited) 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 November 13, 2011 by timo
khaled Posted November 14, 2011 Posted November 14, 2011 \ 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now