Hi :)
Do we always surround escape sequences such as \n and \t by quotation marks? I think this is the case. But I'm almost sure that I've seen \n being used without any quotation marks. Could you please confirm it? Thank you.
do we always surround escape sequences such as \n and \t by quotation marks?
Started by jackson6612, May 31 2011 06:57 PM
3 replies to this topic
#1
Posted 31 May 2011 - 06:57 PM
I'm an outright beginner, learning C++. Using Win XP Pro and Code::Blocks. Be nice to me, please.:)
|
|
|
#2
Posted 31 May 2011 - 08:20 PM
\n is two separate characters and has no real meaning as it is an invalid name of a variable, and not a keyword in C.
The compiler however will detect \ as denoting an escape sequence in a string (conventionally other binary characters could be used that were not exactly printable as \) and uses the next characters as the sequence of the previous escape (n as in newline, r as in carriage return, t as in tab, x00 as in hexadecimal character, ....)
The compiler however will detect \ as denoting an escape sequence in a string (conventionally other binary characters could be used that were not exactly printable as \) and uses the next characters as the sequence of the previous escape (n as in newline, r as in carriage return, t as in tab, x00 as in hexadecimal character, ....)
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#3
Posted 02 June 2011 - 12:21 PM
Alexander said:
\n is two separate characters and has no real meaning as it is an invalid name of a variable
Simply put, it is not a variable, but it certainly does have a real meaning and is not two separate characters, only frequently output as two separate characters by the compiler for the system they are on.
Wow I changed my sig!
#4
Posted 02 June 2011 - 01:52 PM
That is incorrect (based on the compilers we use, of which implement the various standard). The lexer will read the string literal token '\' and then the following character(s) as I have mentioned which is correct to assume in his asking, this includes the \xuuuu added in C99 as I have hinted above. In fact most of the conforming compilers on Windows will store the character in an ignored pointer (non returning token) and iterate the line with ASCII 012 (newline), and will not place a carriage return unless you exactly specify \r\n (and it is incorrect to do so, you can observe this yourself too)
If there are standards that denote otherwise, It would be informative to both of us however if you could show them.
If there are standards that denote otherwise, It would be informative to both of us however if you could show them.
Edited by Alexander, 02 June 2011 - 08:12 PM.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









