HP C A.06.05 Reference Manual

Program Organization
Constants
Chapter 228
represent the null character as \0. This is exactly equivalent to the numeric constant zero (0).
When you use the octal format, you do not need to include the zero prefix as you would for a
normal octal constant.
Multi-Character Constants
Each character in an ordinary character constant takes up one byte of storage; therefore, you
can store up to a 4-byte character constant in a 32-bit integer and up to a 2-byte character
constant in a 16-bit integer.
For example, the following assignments are legal:
{
char x; /* 1-byte integer */
unsigned short int si; /* 2-byte integer */
unsigned long int li; /* 4-byte integer */
/* the following two assignments are portable: */
x = 'j'; /* 1-byte character constant */
li = L'j'; /* 4-byte wide char constant */
/* the following two assignments are not portable,
and are not recommended: */
si = 'ef'; /* 2-character constant */
li = 'abcd'; /* 4-character constant */
}
The variable si is assigned the value of e and f, where each character takes up 8 bits of the
16-bit value. The HP C compiler places the last character in the rightmost (least significant)
byte. Therefore, the constant ef will have a hexadecimal value of 6566. Since the order in
which bytes are assigned is machine dependent, other machines may reverse the order,
assigning f to the most significant byte. In that case, the resulting value would be 6665. For
maximum portability, do not use multi-character constants. Use character arrays instead.
String Constants
A string constant is any series of printable characters or escape characters enclosed in
double quotes. The compiler automatically appends a null character (\0) to the end of the
string so that the size of the array is one greater than the number of characters in the string.
For example,
"A short string"
becomes an array with 15 elements: