You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit f6bca8b
Browse filesBrowse the repository at this point in the historyBrowse files
When initializing scalar types, the value of the *assignment-expression* is assigned to the variable. The conversion rules for assignment apply. (See [Type Conversions](../c-language/type-conversions-c.md) for information on conversion rules.)
9
+
When initializing scalar types, the value of the *`assignment-expression`* is assigned to the variable. The conversion rules for assignment apply. (See [Type Conversions](../c-language/type-conversions-c.md) for information on conversion rules.)
*declarator***=***initializer* /\* For scalar initialization \*/
25
+
*`init-declarator`*:<br/>
26
+
*`declarator`*<br/>
27
+
*`declarator`***`=`***`initializer`* /\* For scalar initialization \*/
28
28
29
-
*initializer*:<br/>
30
-
*assignment-expression*
29
+
*`initializer`*:<br/>
30
+
*`assignment-expression`*
31
31
32
32
You can initialize variables of any type, provided that you obey the following rules:
33
33
34
34
- Variables declared at the file-scope level can be initialized. If you do not explicitly initialize a variable at the external level, it is initialized to 0 by default.
35
35
36
-
- A constant expression can be used to initialize any global variable declared with the **`static`***storage-class-specifier*. Variables declared to be **`static`** are initialized when program execution begins. If you do not explicitly initialize a global **`static`** variable, it is initialized to 0 by default, and every member that has pointer type is assigned a null pointer.
36
+
- A constant expression can be used to initialize any global variable declared with the **`static`***`storage-class-specifier`*. Variables declared to be **`static`** are initialized when program execution begins. If you do not explicitly initialize a global **`static`** variable, it is initialized to 0 by default, and every member that has pointer type is assigned a null pointer.
37
37
38
38
- Variables declared with the **`auto`** or **`register`** storage-class specifier are initialized each time execution control passes to the block in which they are declared. If you omit an initializer from the declaration of an **`auto`** or **`register`** variable, the initial value of the variable is undefined. For automatic and register values, the initializer is not restricted to being a constant; it can be any expression involving previously defined values, even function calls.
39
39
@@ -61,7 +61,7 @@ The pointer `px` is initialized to 0, producing a "null" pointer.
61
61
constint c = (3 * 1024);
62
62
```
63
63
64
-
This example uses a constant expression `(3 * 1024)` to initialize `c` to a constant value that cannot be modified because of the **const** keyword.
64
+
This example uses a constant expression `(3 * 1024)` to initialize `c` to a constant value that cannot be modified because of the **`const`** keyword.
> This syntax for *declaration* is not repeated in the following sections. Syntax in the following sections usually begins with the *declarator* nonterminal.
32
+
> This syntax for *`declaration`* is not repeated in the following sections. Syntax in the following sections usually begins with the *`declarator`* nonterminal.
33
33
34
-
The declarations in the *init-declarator-list* contain the identifiers being named; *init* is an abbreviation for initializer. The *init-declarator-list* is a comma-separated sequence of declarators, each of which can have additional type information, or an initializer, or both. The *declarator* contains the identifiers, if any, being declared. The *declaration-specifiers* nonterminal consists of a sequence of type and storage-class specifiers that indicate the linkage, storage duration, and at least part of the type of the entities that the declarators denote. Therefore, declarations are made up of some combination of storage-class specifiers, type specifiers, type qualifiers, declarators, and initializers.
34
+
The declarations in the *`init-declarator-list`* contain the identifiers being named; *`init`* is an abbreviation for initializer. The *`init-declarator-list`* is a comma-separated sequence of declarators, each of which can have additional type information, or an initializer, or both. The *`declarator`* contains the identifiers, if any, being declared. The *`declaration-specifiers`* nonterminal consists of a sequence of type and storage-class specifiers that indicate the linkage, storage duration, and at least part of the type of the entities that the declarators denote. Declarations are made up of some combination of storage-class specifiers, type specifiers, type qualifiers, declarators, and initializers.
35
35
36
-
Declarations can contain one or more of the optional attributes listed in *attribute-seq*; *seq* is an abbreviation for sequence. These Microsoft-specific attributes perform a variety of functions, which are discussed in detail throughout this book.
36
+
Declarations can contain one or more of the optional attributes listed in *`attribute-seq`*; *`seq`* is an abbreviation for sequence. These Microsoft-specific attributes perform several functions, which are discussed in detail throughout this book.
37
37
38
-
In the general form of a variable declaration, *type-specifier* gives the data type of the variable. The *type-specifier* can be a compound, as when the type is modified by **`const`** or **`volatile`**. The `declarator` gives the name of the variable, possibly modified to declare an array or a pointer type. For example,
38
+
In the general form of a variable declaration, *`type-specifier`* gives the data type of the variable. The *`type-specifier`* can be a compound, as when the type is modified by **`const`** or **`volatile`**. The `declarator` gives the name of the variable, possibly modified to declare an array or a pointer type. For example,
39
39
40
40
```C
41
41
intconst *fp;
@@ -45,17 +45,17 @@ declares a variable named `fp` as a pointer to a nonmodifiable (**`const`**) **`
45
45
46
46
A declaration must have at least one declarator, or its type specifier must declare a structure tag, union tag, or members of an enumeration. Declarators provide any remaining information about an identifier. A declarator is an identifier that can be modified with brackets (**`[ ]`**), asterisks (<strong>`*`</strong>), or parentheses ( **`( )`** ) to declare an array, pointer, or function type, respectively. When you declare simple variables (such as character, integer, and floating-point items), or structures and unions of simple variables, the `declarator` is just an identifier. For more information on declarators, see [Declarators and Variable Declarations](../c-language/declarators-and-variable-declarations.md).
47
47
48
-
All definitions are implicitly declarations, but not all declarations are definitions. For example, variable declarations that begin with the **`extern`** storage-class specifier are "referencing," rather than "defining" declarations. If an external variable is to be referred to before it is defined, or if it is defined in another source file from the one where it is used, an **`extern`** declaration is necessary. Storage is not allocated by "referencing" declarations, nor can variables be initialized in declarations.
48
+
All definitions are implicitly declarations, but not all declarations are definitions. For example, variable declarations that begin with the **`extern`** storage-class specifier are "referencing," rather than "defining" declarations. If an external variable is to be referred to before it's defined, or if it's defined in another source file from the one where it's used, an **`extern`** declaration is necessary. Storage is not allocated by "referencing" declarations, nor can variables be initialized in declarations.
49
49
50
-
A storage class or a type (or both) is required in variable declarations. Except for **`__declspec`**, only one storage-class specifier is allowed in a declaration and not all storage-class specifiers are permitted in every context. The **`__declspec`** storage class is allowed with other storage-class specifiers, and it is allowed more than once. The storage-class specifier of a declaration affects how the declared item is stored and initialized, and which parts of a program can reference the item.
50
+
A storage class or a type (or both) is required in variable declarations. Except for **`__declspec`**, only one storage-class specifier is allowed in a declaration and not all storage-class specifiers are permitted in every context. The **`__declspec`** storage class is allowed with other storage-class specifiers, and it's allowed more than once. The storage-class specifier of a declaration affects how the declared item is stored and initialized, and which parts of a program can reference the item.
51
51
52
-
The *storage-class-specifier* terminals defined in C include **`auto`**, **`extern`**, **`register`**, **`static`**, and **`typedef`**. In addition, Microsoft C includes the *storage-class-specifier* terminal **`__declspec`**. All *storage-class-specifier* terminals except **`typedef`** and **`__declspec`** are discussed in [Storage Classes](../c-language/c-storage-classes.md). See [`typedef` Declarations](../c-language/typedef-declarations.md) for information about **`typedef`**. See[Extended Storage-Class Attributes](../c-language/c-extended-storage-class-attributes.md) for information about **`__declspec`**.
52
+
The *`storage-class-specifier`* terminals defined in C include **`auto`**, **`extern`**, **`register`**, **`static`**, and **`typedef`**. Microsoft C also includes the *`storage-class-specifier`* terminal **`__declspec`**. All *`storage-class-specifier`* terminals except **`typedef`** and **`__declspec`** are discussed in [Storage Classes](../c-language/c-storage-classes.md). For information about **`typedef`**, see [`typedef` Declarations](../c-language/typedef-declarations.md). For information about **`__declspec`**, see[Extended Storage-Class Attributes](../c-language/c-extended-storage-class-attributes.md).
53
53
54
-
The location of the declaration within the source program and the presence or absence of other declarations of the variable are important factors in determining the lifetime of variables. There can be multiple redeclarations but only one definition. However, a definition can appear in more than one translation unit. For objects with internal linkage, this rule applies separately to each translation unit, because internally linked objects are unique to a translation unit. For objects with external linkage, this rule applies to the entire program. See [Lifetime, Scope, Visibility, and Linkage](../c-language/lifetime-scope-visibility-and-linkage.md) for more information about visibility.
54
+
The location of the declaration within the source program and the presence or absence of other declarations of the variable are important factors in determining the lifetime of variables. There can be multiple redeclarations but only one definition. However, a definition can appear in more than one translation unit. For objects with internal linkage, this rule applies separately to each translation unit, because internally linked objects are unique to a translation unit. For objects with external linkage, this rule applies to the entire program. For more information about visibility, see [Lifetime, Scope, Visibility, and Linkage](../c-language/lifetime-scope-visibility-and-linkage.md).
55
55
56
-
Type specifiers provide some information about the data types of identifiers. The default type specifier is **`int`**. For more information, see [Type Specifiers](../c-language/c-type-specifiers.md). Type specifiers can also define type tags, structure and union component names, and enumeration constants. For more information see [Enumeration Declarations](../c-language/c-enumeration-declarations.md), [Structure Declarations](../c-language/structure-declarations.md), and [Union Declarations](../c-language/union-declarations.md).
56
+
Type specifiers provide some information about the data types of identifiers. The default type specifier is **`int`**. For more information, see [Type Specifiers](../c-language/c-type-specifiers.md). Type specifiers can also define type tags, structure and union component names, and enumeration constants. For more information, see [Enumeration Declarations](../c-language/c-enumeration-declarations.md), [Structure Declarations](../c-language/structure-declarations.md), and [Union Declarations](../c-language/union-declarations.md).
57
57
58
-
There are two *type-qualifier* terminals: **`const`** and **`volatile`**. These qualifiers specify additional properties of types that are relevant only when accessing objects of that type through l-values. For more information on **`const`** and **`volatile`**, see [Type Qualifiers](../c-language/type-qualifiers.md). For a definition of l-values, see [L-Value and R-Value Expressions](../c-language/l-value-and-r-value-expressions.md).
58
+
There are two *`type-qualifier`* terminals: **`const`** and **`volatile`**. These qualifiers specify additional properties of types that are relevant only when accessing objects of that type through l-values. For more information on **`const`** and **`volatile`**, see [Type Qualifiers](../c-language/type-qualifiers.md). For a definition of l-values, see [L-Value and R-Value Expressions](../c-language/l-value-and-r-value-expressions.md).
0 commit comments