What are character literals?

September 21st, 2007 by uCertify Leave a reply »

Character literals are 16 bit Unicode characters that are used to represent a single character. They are generally used to initialize variables declared as char. They can also be converted into integer types and manipulated with integer operators.

Character literals are formed by enclosing a single printable character or the escape sequence for a character within a pair of single quotes. A character literal can be formed using any of the four options given below:

  1. Printable characters available on the keyboard: A character literal can be formed using a printable character available on the keyboard except the backslash and single quote characters. For example: ‘a’,’ A’, ‘#’, etc.
  2. Special escape sequences: Some special characters are defined using escape sequences. The escape sequences for these characters are shown below:

    Escape sequence Description
    Single quote
    \” Double quote
    Backslash
    r Carriage return
    n New line
    f Form feed
    t Tab
    \ Backspace
  3. A character literal can be formed using one of the escape sequences given in the table.

  4. Unicode escape sequences: A Unicode escape sequence consists of backslash-u (u) characters followed by the hexadecimal representation of the Unicode character. The syntax used to represent the Unicode values for characters is uxxxx where, each x represents a hexadecimal digit. The range of the hexadecimal escape sequence is from u0000 to uffff.

    There are few Unicode sequences that cannot be used to form a character literal. These are shown below:

    u0027    (this represents a single quote)
    u000a    (this represents a line feed)
    u000d    (this represents a carriage return)
    u005c    (this represents a backslash)

  5. Octal escape sequences: Any Unicode character whose value ranges from 0 to 255 can be represented using octal escape sequences. An octal escape sequence consists of a backslash character followed by three octal digits. The range of the octal sequence is from 00 to 377.
  • Share/Bookmark
Advertisement

Leave a Reply

uCertify.com | Our Company | Articles | Contact Us | News and Press Release | uCertify India | Entries (RSS)
MCSE: MCSA, MCTS, MCITP    JAVA Certification: SCJP, SCWCD    Cisco Certification: CCNA, CCENT    A+, Network+, Security+ Project+
Oracle Certification: OCP 11g, OCP 10g, OCA 11g, OCA 10g    CIW foundation    EC-212-32,    CISSP    Photoshop ACE CS4    Adobe Flash ACE, PMP, CAPM
© 2008 uCertify.com. All rights reserved. All trademarks are the property of their respective owners.