blogger Indonesia

Follow judhyns blog

THE char TYPE

Introduction

Alpha characters are stored internally as integers. Since each character can have 8 bits, you can have 256 different character values (0–255). Each integer is associated with a character using a character set. The most commonly used character set is ASCII. In ASCII, "A" is represented as decimal value 65, octal value 101, or hexadecimal value 41.

Explanation

If you declared C as a character as

char c; 

then you can assign A as follows:

c = 'A'; c = 65; c = '\x41';   // Hexadecimal representation
c = '\101'; // Octal representation

You cannot write c = ‘A’ because ‘A’ is interpreted as a string.

Escape Sequence

Certain characters are not printable but can be used to give directive to functions such as printf. For example, to move printing to the next line you can use the character "\n". These characters are called escape sequences. Though the escape sequences look like two characters, each represents only a single character.

The complete selection of escape sequences is shown here.

\a

alert (bell) character

\\

backslash

\b

backspace

\?

question mark

\f

form feed

\’

single quote

\n

new line

\"

double quote

\r

carriage return

\ooo

octal number

\t

horizontal tab

\xhh

hexadecimal number

\v

vertical tab



Points to Remember

  1. Characters are stored as a set of 255 integers and the integer value is interpreted according to the character set.

  2. The most common character set is ASCII.

  3. You can give directive to functions such as printf by using escape sequence characters.

No comments:

feed

PR Check

activesearchresults

judhyn's blog

 

http://www.judhyn.blogspot.com | |