Initializers

An initializer specifies an initial value to a data object and is optional in a data declaration. Whether an initializer is valid for a particular declaration depends on the type and storage class of the object to be initialized.

The initializer consists of the = symbol followed by an initial expression or a brace-enclosed list of initial expressions separated by commas. Individual expressions must be separated by commas, and groups of expressions can be enclosed in braces and separated by commas. Braces ({ }) are optional if the initializer for a character string is a string literal. The number of initializers must not be greater than the number of elements to be initialized. The initial expression evaluates to the first value of the data object.

To assign a value to an arithmetic or pointer type, use the simple initializer: = expression. For example, the following data definition uses the initializer = 3 to set the initial value of group to 3:
      int group = 3;
You initialize a variable of character type with a character literal (consisting of one character) or with an expression that evaluates to an integer.

C++ onlyYou can initialize variables at namespace scope with nonconstant expressions. C++ onlyC only You cannot initialize variables at global scope with nonconstant expressions.C only