Tripod C Now
Literal Constants
November 25, 1999
John's home page

C Literal Constants
Type BaseExampleDescription
char * character"hello" Any string of characters enclosed in double quotes (") (see Note 1)
int character'1'Any single character in single quotes (')
octal01Any octal number (digits 0-7) beginning with a 0 (zero)
decimal1Any number (digits 0-9) not beginning with a 0 (zero)
hexadecimal0x1L 0X (zero X) or 0x (zero x) followed by any hexadecimal number (digits 0-F)
unsigned octal01U Any octal number (digits 0-7) beginning with a 0 (zero) and followed by U or u
decimal1U Any number (digits 0-9) not beginning with a 0 (zero) and followed by U or u
hexadecimal0x1U 0X (zero X) or 0x (zero x) followed by any hexadecimal number (digits 0-F) followed by U or u
long octal01LAny octal number (digits 0-7) beginning with a 0 (zero) and followed by L or l
decimal1LAny number (digits 0-9) not beginning with a 0 (zero) and followed by L or l
hexadecimal0x1L 0X (zero X) or 0x (zero x) followed by any hexadeciaml number (digits 0-F) followed by L or l
unsigned long octal01ULAny octal number (digits 0-7) beginning with a 0 (zero) and followed by U or u and L or l
decimal1ULAny number (digits 0-9) not beginning with a 0 (zero) and followed by U or u and L or l
hexadecimal0x1UL 0X (zero X) or 0x (zero x) followed by any hexadeciaml number (digits 0-F) followed by U or u and L or l
float decimal12.3 Any number (digits 0-9) containing a decimal point (.)
decimal12E1 Any number (digits 0-9) followed by E or e and followed by an exponent of 10 (12E1 = 12 * 101 = 120.)

Escape Sequences (see Note 2)
Code CharacterDescription
\a BELAudible alert
\b BSBackspace
\f FFForm Feed
\n LFNew Line
\r CRCarriage Return
\t HTHorizontal Tab
\v VTVertical Tab
\\ \Backslash
\' 'Single Quote
\" "Double Quote
\0 NULLBinary zero
\nnn AnyThree octal (0-7) digits following the backslash are interpreted as an octal number and stored in a single byte.
\xnn AnyTwo hexadecimal (0-F) digits following the backslash x are interpreted as a hexadecimal number and stored in a single byte.

Notes:
  1. String constants are stored as the literal characters followed by a byte of binary 0.  The value returned is a pointer to the first character.
  2. Escape sequences are coded within a character constant or a string constant, to represent non-printable and certain printable characters.  They are stored as a single character.

C Now C Reference Index
C Now Home Page