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/cpp/additive-operators-plus-and.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -59,7 +59,7 @@ expression - expression
59
59
60
60
## Example
61
61
62
-
```
62
+
```cpp
63
63
// expre_Additive_Operators.cpp
64
64
// compile with: /EHsc
65
65
#include<iostream>
@@ -80,7 +80,7 @@ int main() {
80
80
## Pointer addition
81
81
If one of the operands in an addition operation is a pointer to an array of objects, the other must be of integral type. The result is a pointer that is of the same type as the original pointer and that points to another array element. The following code fragment illustrates this concept:
82
82
83
-
```
83
+
```cpp
84
84
short IntArray[10]; // Objects of type short occupy 2 bytes
Copy file name to clipboardExpand all lines: docs/cpp/address-of-operator-amp.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,7 +28,7 @@ ms.workload: ["cplusplus"]
28
28
29
29
When the address-of operator is applied to a [qualified name](http://msdn.microsoft.com/en-us/3fefb16d-8120-4627-8b3f-3d90fbdcd1df), the result depends on whether the *qualified-name* specifies a static member. If so, the result is a pointer to the type specified in the declaration of the member. If the member is not static, the result is a pointer to the member *name* of the class indicated by *qualified-class-name*. (See [Primary Expressions](../cpp/primary-expressions.md) for more about *qualified-class-name*.) The following code fragment shows how the result differs, depending on whether the member is static:
30
30
31
-
```
31
+
```cpp
32
32
// expre_Address_Of_Operator.cpp
33
33
// C2440 expected
34
34
classPTM {
@@ -52,7 +52,7 @@ int main() {
52
52
53
53
## Example
54
54
55
-
```
55
+
```cpp
56
56
// expre_Address_Of_Operator2.cpp
57
57
// compile with: /EHsc
58
58
#include <iostream>
@@ -75,7 +75,7 @@ int main() {
75
75
76
76
The following example uses the address-of operator to pass a pointer argument to a function:
Copy file name to clipboardExpand all lines: docs/cpp/aliases-and-typedefs-cpp.md
+19-19Lines changed: 19 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -147,7 +147,7 @@ int main ()
147
147
148
148
Names declared using `typedef` occupy the same namespace as other identifiers (except statement labels). Therefore, they cannot use the same identifier as a previously declared name, except in a class-type declaration. Consider the following example:
149
149
150
-
```
150
+
```cpp
151
151
// typedef_names1.cpp
152
152
// C2377 expected
153
153
typedefunsignedlongUL; // Declare a typedef name, UL.
@@ -156,7 +156,7 @@ int UL; // C2377: redefined.
156
156
157
157
The name-hiding rules that pertain to other identifiers also govern the visibility of names declared using `typedef`. Therefore, the following example is legal in C++:
158
158
159
-
```
159
+
```cpp
160
160
// typedef_names2.cpp
161
161
typedefunsignedlongUL; // Declare a typedef name, UL
162
162
intmain()
@@ -168,7 +168,7 @@ int main()
168
168
```
169
169
170
170
171
-
```
171
+
```cpp
172
172
// typedef_specifier1.cpp
173
173
typedefchar FlagType;
174
174
@@ -184,26 +184,26 @@ void myproc( int )
184
184
185
185
When declaring a local-scope identifier by the same name as a typedef, or when declaring a member of a structure or union in the same scope or in an inner scope, the type specifier must be specified. For example:
186
186
187
-
```
187
+
```cpp
188
188
typedef char FlagType;
189
189
const FlagType x;
190
190
```
191
191
192
192
To reuse the `FlagType` name for an identifier, a structure member, or a union member, the type must be provided:
193
193
194
-
```
194
+
```cpp
195
195
constint FlagType; // Type specifier required
196
196
```
197
197
198
198
It is not sufficient to say
199
199
200
-
```
200
+
```cpp
201
201
const FlagType; // Incomplete specification
202
202
```
203
203
204
204
because the `FlagType` is taken to be part of the type, not an identifier that is being redeclared. This declaration is taken to be an illegal declaration like
205
205
206
-
```
206
+
```cpp
207
207
int; // Illegal declaration
208
208
```
209
209
@@ -222,25 +222,25 @@ ulong ul; // Equivalent to "unsigned long ul;"
222
222
223
223
To use `typedef` to specify fundamental and derived types in the same declaration, you can separate declarators with commas. For example:
224
224
225
-
```
225
+
```cpp
226
226
typedef char CHAR, *PSTR;
227
227
```
228
228
229
229
The following example provides the type `DRAWF` for a function returning no value and taking two int arguments:
230
230
231
-
```
231
+
```cpp
232
232
typedefvoidDRAWF( int, int );
233
233
```
234
234
235
235
After the above `typedef` statement, the declaration
236
236
237
-
```
237
+
```cpp
238
238
DRAWF box;
239
239
```
240
240
241
241
would be equivalent to the declaration
242
242
243
-
```
243
+
```cpp
244
244
voidbox( int, int );
245
245
```
246
246
@@ -263,11 +263,11 @@ int main()
263
263
ms.f = 0.99;
264
264
printf_s("%d %f\n", ms.i, ms.f);
265
265
}
266
-
```
266
+
```cpp
267
267
268
268
```Output
269
269
10 0.990000
270
-
```
270
+
```cpp
271
271
272
272
### Re-declaration of typedefs
273
273
The `typedef` declaration can be used to redeclare the same name to refer to the same type. For example:
@@ -282,7 +282,7 @@ typedef char CHAR;
282
282
// PROG.CPP
283
283
#include "file1.h"
284
284
#include "file2.h" // OK
285
-
```
285
+
```cpp
286
286
287
287
The program PROG.CPP includes two header files, both of which contain `typedef` declarations for the name `CHAR`. As long as both declarations refer to the same type, such redeclaration is acceptable.
288
288
@@ -291,7 +291,7 @@ typedef char CHAR;
291
291
```cpp
292
292
// FILE2.H
293
293
typedef int CHAR; // Error
294
-
```
294
+
```cpp
295
295
296
296
the compiler issues an error because of the attempt to redeclare the name `CHAR` to refer to a different type. This extends to constructs such as:
297
297
@@ -304,7 +304,7 @@ typedef union REGS // OK: name REGS redeclared
304
304
struct wordregs x; // same meaning.
305
305
struct byteregs h;
306
306
} REGS;
307
-
```
307
+
```cpp
308
308
309
309
### typedefs in C++ vs. C
310
310
Use of the `typedef` specifier with class types is supported largely because of the ANSI C practice of declaring unnamed structures in `typedef` declarations. For example, many C programmers use the following:
@@ -317,17 +317,17 @@ typedef struct { // Declare an unnamed structure and give it the
317
317
unsigned x;
318
318
unsigned y;
319
319
} POINT;
320
-
```
320
+
```cpp
321
321
322
322
The advantage of such a declaration is that it enables declarations like:
Copy file name to clipboardExpand all lines: docs/cpp/alignment-cpp-declarations.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,7 +26,7 @@ One of the low-level features of C++ is the ability to specify the precise align
26
26
27
27
In addition, the compiler pads structures in a way that naturally aligns each element of the structure. Consider the structure struct x_ in the following code example:
28
28
29
-
```
29
+
```cpp
30
30
structx_
31
31
{
32
32
char a; // 1 byte
@@ -41,7 +41,7 @@ struct x_
41
41
42
42
The following code example shows how the compiler places the padded structure in memory:Copy
typedef __declspec(align(32)) struct { int a; } S;
54
54
```
55
55
56
56
`__alignof(S)` is equal to `32`.
57
57
58
58
One use for `__alignof` would be as a parameter to one of your own memory-allocation routines. For example, given the following defined structure `S`, you could call a memory-allocation routine named `aligned_malloc` to allocate memory on a particular alignment boundary.
59
59
60
-
```
60
+
```cpp
61
61
typedef__declspec(align(32)) struct { int a; double b; } S;
62
62
int n = 50; // array size
63
63
S* p = (S*)aligned_malloc(n * sizeof(S), __alignof(S));
Copy file name to clipboardExpand all lines: docs/cpp/anonymous-class-types.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@ ms.workload: ["cplusplus"]
14
14
# Anonymous Class Types
15
15
Classes can be anonymous — that is, they can be declared without an *identifier*. This is useful when you replace a class name with a `typedef` name, as in the following:
16
16
17
-
```
17
+
```cpp
18
18
typedefstruct
19
19
{
20
20
unsigned x;
@@ -27,7 +27,7 @@ typedef struct
27
27
28
28
Anonymous classes are also useful when you want a reference to a class member to appear as though it were not contained in a separate class, as in the following:
29
29
30
-
```
30
+
```cpp
31
31
structPTValue
32
32
{
33
33
POINT ptLoc;
@@ -43,7 +43,7 @@ PTValue ptv;
43
43
44
44
In the preceding code, `iValue` can be accessed using the object member-selection operator (**.**) as follows:
45
45
46
-
```
46
+
```cpp
47
47
int i = ptv.iValue;
48
48
```
49
49
@@ -62,7 +62,7 @@ int i = ptv.iValue;
62
62
63
63
You can access the members of an anonymous structure as if they were members in the containing structure.
Copy file name to clipboardExpand all lines: docs/cpp/argument-dependent-name-koenig-lookup-on-functions.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@ The compiler can use argument-dependent name lookup to find the definition of an
17
17
## Example
18
18
In the sample, the compiler notes that function `f()` takes an argument `x`. Argument `x` is of type `A::X`, which is defined in namespace `A`. The compiler searches namespace `A` and finds a definition for function `f()` that takes an argument of type `A::X`.
The following example shows how to define an array at run time:
47
47
48
-
```
48
+
```cpp
49
49
// arrays.cpp
50
50
// compile with: /EHsc
51
51
#include<iostream>
@@ -70,7 +70,7 @@ int main() {
70
70
71
71
Arrays constructed from other arrays are multidimensional arrays. These multidimensional arrays are specified by placing multiple bracketed constant expressions in sequence. For example, consider this declaration:
72
72
73
-
```
73
+
```cpp
74
74
int i2[5][7];
75
75
```
76
76
@@ -81,7 +81,7 @@ Conceptual Layout of Multidimensional Array
81
81
82
82
In declarations of multidimensioned arrays that have an initializer list (as described in [Initializers](../cpp/initializers.md)), the constant expression that specifies the bounds for the first dimension can be omitted. For example:
The technique of omitting the bounds specification for the first dimension of a multidimensional array can also be used in function declarations as follows:
0 commit comments