HP C A.06.05 Reference Manual
Data Types and Declarations
Initialization
Chapter 3 65
char *cp = "hello";
This declares the object cp as a character pointer initialized to point to the first character of
the string “hello”.
It is illegal to specify more initializes in a list than are required to initialize the specified
aggregate. The one exception to this rule is the initialization of an array of characters with a
string literal.
char t[3] = "cat";
This initializes the array t to contain the characters c, a, and t. The trailing '\0' character is
ignored.
If there are not enough initializes, the remainder of the aggregate is initialized to zero.
Some more examples include:
char *errors[ ] = {
"undefined file",
"input error",
"invalid user"
};
In this example, the array errors is an array of pointers to character (strings). The array is
initialized with the starting addresses of three strings, which will be interpreted as error
messages.
An array with element type compatible with wchar_t (unsigned
int) may be initialized by a wide string literal, optionally enclosed in braces. Successive
characters of the wide string literal initialize the members of the array. This includes the
terminating zero-valued character, if there is room or if the array is of unknown size.
Examples
wchar_t wide_message[ ]=L"x$$z";
You initialize structures as you do any other aggregate:
struct{
int i;
unsigned u:3;
unsigned v:5;
float f;
char *p;
} s[ ] = {