Converted from .HLP to .HTML by HLPTOHTML.

cc .HLP

Array

An array is an aggregate of subscripted elements of the same type. Elements of an array can have one of the fundamental data types or can be structures, unions, or other arrays (multidimensional arrays). An array is declared using square brackets. The following example declares array1 to be an array of 10 integers. The valid subscripts for array1 range from 0 to 9.

int array1[10];

The next example declares array2 to be a two-dimensional (2 by 3) array of integers:

int array2[2][3];

The elements are stored in row-major order as follows:

array2[0][0], array2[0][1], ... array2[1][2].

enum

Enumerated types are sets of scalar objects that have type names. Variables are declared with enum-specifiers in the place of the type specifier. The forms of enum-specifier are as follows:

enum { enumerator,... } or enum tag { enumerator,... } or enum tag

Each enumerator defines a constant of the enumerated type (tag). The enumerator list forms an ordered list of the type's values. Each enumerator has the form "identifier [= expression]", where the "identifier" is the name to be used for the constant value and the optional "expression" gives its integer equivalent. If a tag appears but no list of enumerators, the enum-specifier refers to a previous definition of the enumerated type, identified by the tag.

Pointer

A pointer in C is a variable that holds the address of another variable. Pointers are declared with the asterisk operator as follows:

int i, *ip, *np; /* i IS AN INTEGER, ip AND np ARE POINTERS TO INTEGERS */

The following operations are permitted on pointers:

o Assigning an address to the pointer (as in ip = &i;)

o Fetching the object of the pointer (by dereferencing the pointer) with the asterisk operator (i = *ip;, which assigns the addressed integer to i)

o Adding (as in ip += 5;, which makes ip point to the object that is five longwords away from the initial address in ip)

o Subtracting (as in i = np - ip;, which gives the number of objects separating the objects pointed to by np and ip)

Structure

A structure is an aggregate of members whose data types can differ. Members can be scalar variables, arrays, structures, unions, and pointers to any object. The size of a structure is the sum of the sizes of its members, which are stored in the order of their declarations. Structures are defined with the keyword struct, followed by an optional tag, followed by a structure-declaration list in braces. The syntax is as follows:

struct [identifier] { struct-declaration ... }

Each struct-declaration is a type specifier (type keyword, struct tag, union tag, enum tag, or typedef name) followed by a list of member declarators. The syntax is as follows:

type-specifier member-declarator,... ;

Each member declarator defines either an ordinary variable or a bit field. The syntax is as follows:

declarator or [declarator] : constant-expression

typedef

Use the typedef keyword to define an abbreviated name, or synonym, for a lengthy type definition. Grammatically, typedef is a storage-class specifier, so it can precede any valid declaration. In such a declaration, the identifiers name types instead of variables. For example:

typedef char CH, *CP, STRING[10], CF();

In the scope of this declaration, CH is a synonym for "character," CP for "pointer to character," STRING for "10-element array of characters," and CF for "function returning a character." Each of the type definitions can be used in that scope to declare variables. For example:

CF c; /* c IS A FUNCTION RETURNING A CHARACTER */ STRING s; /* s IS A 10-CHARACTER STRING */

Union

A union is an aggregate of members whose data types can differ. Members can be scalar variables, arrays, structures, unions, and pointers to any object. The size of a union is the size of its longest member; all its members occupy the same storage. Unions are defined with the union keyword, followed by an optional tag, followed by a union-declaration list in braces. The syntax is as follows:

union [identifier] { union-declaration ... }

Each union-declaration is a type specifier (type keyword, struct tag, union tag, enum tag, or typedef name) followed by a list of member declarators. The syntax is as follows:

type-specifier member-declarator,... ;

Each member declarator defines either an ordinary variable or a bit field. The syntax is as follows:

declarator or [declarator] : constant-expression

Void

You can use the void data type to declare functions that do not return a value. Functions declared to be of this type cannot contain return statements and cannot be used in statements where a return value is expected. The void data type can be used in the cast operation if casting to a "function without a return value ..." You can also use the void data type with pointers.