What are character literals?

Are you preparing for IT certification? With practice questions, study notes, interactive quizzes, tips and technical articles, uCertify PrepKits ensure that you get a solid grasp of core technical concepts to ace your certification exam in first attempt.

What are character literals?

Rating:

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
    Carriage return
    New line
    f Form feed
    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.


Rating:



Other articles

Click here to Article home

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