tags:

views:

40

answers:

1

1) Escape sequences are mostly used for characters constants that either have a special meaning (such as or \ ) or for characters that can't be represented graphically. Any character literal could be represented using hex ('\xhhhh') or unicode ('\0hhhh') escape sequences. Is there a situation where we should prefer using hex escape sequence over unicode escape sequence or vice versa?

2) When should we specify integer literals in hexadecimal form?

thank you

+3  A: 

They are not interchangeable. You can only use a Unicode escape in an identifier name:

        var on\u0065 = 1;
        var tw\x006f = 2;  // bad

But in a string or char literal it doesn't make a heck of a lot of difference. I prefer \u myself because the escape code has a fixed number of digits, \x is variable. But easy enough to avoid mistakes. Also note /U to pick codepoints from the upper planes.

Hans Passant
I'm shocked that the first example compiles (yeah, I just tried it now) and can't really think of a good situation to use it, as in programming English is more popular ((see http://www.codinghorror.com/blog/2009/03/the-ugly-american-programmer.html) Perhaps 2 * \u03C0 * r?
Sam
thanx for helping me
flockofcode