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
Copy file name to clipboardExpand all lines: docs/c-language/interpreting-more-complex-declarators.md
+10-10Lines changed: 10 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -47,31 +47,31 @@ In this example, the steps are numbered in order and can be interpreted as follo
47
47
48
48
The following examples illustrate other complex declarations and show how parentheses can affect the meaning of a declaration.
49
49
50
-
```
50
+
```C
51
51
int *var[5]; /* Array of pointers to int values */
52
52
```
53
53
54
54
The array modifier has higher priority than the pointer modifier, so `var` is declared to be an array. The pointer modifier applies to the type of the array elements; therefore, the array elements are pointers to **`int`** values.
55
55
56
-
```
56
+
```C
57
57
int (*var)[5]; /* Pointer to array of int values */
58
58
```
59
59
60
60
In this declaration for `var`, parentheses give the pointer modifier higher priority than the array modifier, and `var` is declared to be a pointer to an array of five **`int`** values.
61
61
62
-
```
62
+
```C
63
63
long *var( long, long ); /* Function returning pointer to long */
64
64
```
65
65
66
66
Function modifiers also have higher priority than pointer modifiers, so this declaration for `var` declares `var` to be a function returning a pointer to a **`long`** value. The function is declared to take two **`long`** values as arguments.
67
67
68
-
```
68
+
```C
69
69
long (*var)( long, long ); /* Pointer to function returning long */
70
70
```
71
71
72
72
This example is similar to the previous one. Parentheses give the pointer modifier higher priority than the function modifier, and `var` is declared to be a pointer to a function that returns a **`long`** value. Again, the function takes two **`long`** arguments.
73
73
74
-
```
74
+
```C
75
75
struct both /* Array of pointers to functions */
76
76
{ /* returning structures */
77
77
int a;
@@ -81,28 +81,28 @@ struct both /* Array of pointers to functions */
81
81
82
82
The elements of an array cannot be functions, but this declaration demonstrates how to declare an array of pointers to functions instead. In this example, `var` is declared to be an array of five pointers to functions that return structures with two members. The arguments to the functions are declared to be two structures with the same structure type, `both`. Note that the parentheses surrounding `*var[5]` are required. Without them, the declaration is an illegal attempt to declare an array of functions, as shown below:
83
83
84
-
```
84
+
```C
85
85
/* ILLEGAL */
86
86
struct both *var[5](struct both, struct both);
87
87
```
88
88
89
89
The following statement declares an array of pointers.
90
90
91
-
```
91
+
```C
92
92
unsignedint *(* const *name[5][10] ) ( void );
93
93
```
94
94
95
95
The `name` array has 50 elements organized in a multidimensional array. The elements are pointers to a pointer that is a constant. This constant pointer points to a function that has no parameters and returns a pointer to an unsigned type.
96
96
97
97
This next example is a function returning a pointer to an array of three **`double`** values.
98
98
99
-
```
99
+
```C
100
100
double ( *var( double (*)[3] ) )[3];
101
101
```
102
102
103
103
In this declaration, a function returns a pointer to an array, since functions returning arrays are illegal. Here `var` is declared to be a function returning a pointer to an array of three **`double`** values. The function `var` takes one argument. The argument, like the return value, is a pointer to an array of three **`double`** values. The argument type is given by a complex *abstract-declarator*. The parentheses around the asterisk in the argument type are required; without them, the argument type would be an array of three pointers to **`double`** values. For a discussion and examples of abstract declarators, see [Abstract Declarators](../c-language/c-abstract-declarators.md).
104
104
105
-
```
105
+
```C
106
106
union sign /* Array of arrays of pointers */
107
107
{ /* to pointers to unions */
108
108
int x;
@@ -112,7 +112,7 @@ union sign /* Array of arrays of pointers */
112
112
113
113
As the above example shows, a pointer can point to another pointer, and an array can contain arrays as elements. Here `var` is an array of five elements. Each element is a five-element array of pointers to pointers to unions with two members.
114
114
115
-
```
115
+
```C
116
116
union sign *(*var[5])[5]; /* Array of pointers to arrays
0 commit comments