Skip to content

Commit 97755cf

Browse files
openpublishbuildColin Robertson
authored andcommitted
Confirm merge from FromPublicMasterBranch to master to sync with https://github.com/MicrosoftDocs/cpp-docs (branch master) (#615)
* Update cricheditctrl-class.md LineLength is a wrapper of EM_LINELENGTH, which returns length in characters not bytes. * Update csettingsstore-class.md contraction between the meaning of bAdmin in the parameters and remarks section of CSettingsStore::CSettingsStore * Update clistbox-class_23.cpp the buffer required by later code would be 16 bytes in ANSI and 32 bytes in Unicode, preallocating 10 bytes is useless. * Fix unwind opcode values * Update algorithm.md Fix minor typo in Remarks section * Undesired indentation in CFile. Fix for undesired indentation in CFile constructor documentation. * Update cricheditctrl-class.md clarify that length is in TCHARs, add situations when index is out of bound, and when there's a carriage return based on EM_LINELENGTH docs * Update compiler-warning-level-4-c4295.md Clarify warning intent and ways to fix it, per comment by Kinichiro_Inoguchi * Fix type error on the namespace * Merge to live for offline publishing (MicrosoftDocs#532) * Confirm merge from FromPublicMasterBranch to master to sync with https://github.com/MicrosoftDocs/cpp-docs (branch master) (#527) * Update cricheditctrl-class.md LineLength is a wrapper of EM_LINELENGTH, which returns length in characters not bytes. * Update csettingsstore-class.md contraction between the meaning of bAdmin in the parameters and remarks section of CSettingsStore::CSettingsStore * Update clistbox-class_23.cpp the buffer required by later code would be 16 bytes in ANSI and 32 bytes in Unicode, preallocating 10 bytes is useless. * Fix unwind opcode values * Update algorithm.md Fix minor typo in Remarks section * Undesired indentation in CFile. Fix for undesired indentation in CFile constructor documentation. * Update cricheditctrl-class.md clarify that length is in TCHARs, add situations when index is out of bound, and when there's a carriage return based on EM_LINELENGTH docs * Update compiler-warning-level-4-c4295.md Clarify warning intent and ways to fix it, per comment by Kinichiro_Inoguchi * Fix type error on the namespace * Add /Zc:ternary switch docs (#525) * Create topic, not linked yet * Include links in TOC and overview * Fix dash * Add link to Zc:ternary to permissive * Fix link typo * fixed up art files for VC++ directories (#529) * CMake updates for 15.6 (#524) * added new content on cmake cache import * added new art for cmake * updates to cmake tools intro * new art for 15.6 updates * updates for environment variables and inherited environments * proofreading pass * updated art for what's new page (MicrosoftDocs#528) * Second attempt at merge (#531) * added new content on cmake cache import * added new art for cmake * updates to cmake tools intro * new art for 15.6 updates * updates for environment variables and inherited environments * proofreading pass * Update cmake-tools-for-visual-cpp.md (MicrosoftDocs#530) I played editor in this file. I only meant to change one thing, but it was hard to stop. * [mkdir-wmkdir.md] Fix wrong indentation Remove redundant spaces in the code. * Change integer limits and header name to use standard names. * Fix double code quote. * Fix indentation [ _rotl ] * Update get-wpgmptr.md Mention entry point restriction on using _get_wpgmptr() - only for programs for wide entry points. * Update get-pgmptr.md Mention entry point restriction on calling _get_pgmptr * Fix formatting * Remove __declspec(noalias) from example Remove __declspec(noalias) from example to make it clearer what is going on. I'm submitting a second PR that updates __declspec(alias) to have its own example. Clean up other text. * Remove __declspec(restrict) from example Remove __declspec(restrict) from example to make it clearer what is going on. I'm submitting a second PR that updates __declspec(restrict) to have its own example. Clean up other text. * Update compiler-error-c2512.md Expand explanations to address some common confusion. Remove examples that now generate different errors. * Update date for changed article * Update date, formatting and some wording. * Update date, additional language cleanup * Update char-wchar-t-char16-t-char32-t.md Address issue #169 Fix dangling "Unicode is the" fragment. Expand explanation of types and where they are used. * Update char-wchar-t-char16-t-char32-t.md Fix date and pointer/array mention. * Fix links to samples and interface * "Users" of the C++ compiler are "developers" Users of the C++ compiler are generally developers. Isn't it a bit more precise and a bit more humanizing to refer to them as such? * Typo fixed in __popcnt * Update indirection-and-address-of-operators.md Bring descriptions into compliance with C99 standard (as of 2007). Fix some formatting issues. * Update configuring-programs-for-windows-xp.md Fix typo. * Update set-se-translator.md (MicrosoftDocs#176) * Update set-se-translator.md Update example with a more complicated pattern so that the compiler doesn't optimize out the exception generation when directed to be optimizing. Moved _set_se_translator out of the "try" as having it is very dangerous because it's possible an exception occurs beforehand and this function would not be called. Fixed spacing issues in code examples. * Update set-se-translator.md Modernize code examples slightly, build /W4 clean. Clean up formatting, lint markdown. * Update date in _set_se_translator.md Missed the date earlier. * Fix date some more in _set_se_translator * Update c4473.md Fix missing "the"
1 parent 2a7369c commit 97755cf

File tree

3 files changed

+248
-234
lines changed

3 files changed

+248
-234
lines changed
Lines changed: 64 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "Indirection and Address-of Operators | Microsoft Docs"
33
ms.custom: ""
4-
ms.date: "11/04/2016"
4+
ms.date: "02/16/2018"
55
ms.reviewer: ""
66
ms.suite: ""
77
ms.technology: ["cpp-language"]
@@ -17,65 +17,67 @@ manager: "ghogen"
1717
ms.workload: ["cplusplus"]
1818
---
1919
# Indirection and Address-of Operators
20-
The indirection operator (**\***) accesses a value indirectly, through a pointer. The operand must be a pointer value. The result of the operation is the value addressed by the operand; that is, the value at the address to which its operand points. The type of the result is the type that the operand addresses.
21-
22-
If the operand points to a function, the result is a function designator. If it points to a storage location, the result is an l-value designating the storage location.
23-
24-
If the pointer value is invalid, the result is undefined. The following list includes some of the most common conditions that invalidate a pointer value.
25-
26-
- The pointer is a null pointer.
27-
28-
- The pointer specifies the address of a local item that is not visible at the time of the reference.
29-
30-
- The pointer specifies an address that is inappropriately aligned for the type of the object pointed to.
31-
32-
- The pointer specifies an address not used by the executing program.
33-
34-
The address-of operator (**&**) gives the address of its operand. The operand of the address-of operator can be either a function designator or an l-value that designates an object that is not a bit field and is not declared with the **register** storage-class specifier.
35-
36-
The result of the address operation is a pointer to the operand. The type addressed by the pointer is the type of the operand.
37-
38-
The address-of operator can only be applied to variables with fundamental, structure, or union types that are declared at the file-scope level, or to subscripted array references. In these expressions, a constant expression that does not include the address-of operator can be added to or subtracted from the address expression.
39-
40-
## Examples
41-
The following examples use these declarations:
42-
20+
21+
The unary indirection operator (__*__) accesses a value indirectly, through a pointer. The operand must be a pointer type. The result of the operation is the value addressed by the operand; that is, the value at the address to which its operand points. The type of the result is the type that the operand addresses.
22+
23+
The result of the indirection operator is *type* if the operand is of type *pointer to type*. If the operand points to a function, the result is a function designator. If it points to an object, the result is an lvalue that designates the object.
24+
25+
If the pointer value is not valid, the result of the indirection operator is undefined. These are some of the most common conditions that invalidate a pointer value:
26+
27+
- The pointer is a null pointer.
28+
29+
- The pointer specifies the address of an object after the end of its lifetime (such as an object that's gone out of scope or that's been deallocated) at the time of the reference.
30+
31+
- The pointer specifies an address that is inappropriately aligned for the type of the object pointed to.
32+
33+
- The pointer specifies an address not used by the executing program.
34+
35+
The unary address-of operator (**&**) gives the address of its operand. The operand must be either an lvalue that designates an object that is not declared __register__ and is not a bit-field, or the result of a unary __*__ operator or an array dereference (__[]__) operator, or a function designator. The result is of type *pointer to type* for an operand of type *type*.
36+
37+
If the operand is the result of a unary __*__ operator, neither operator is evaluated and the result is as if both were omitted. The result is not an lvalue, and the constraints on the operators still apply. If the operand is the result of a __[]__ operator, neither the __&__ operator nor the unary __*__ implied by the __[]__ operator is evaluated. The result has the same effect as removing the __&__ operator and changing the __[]__ operator to a __+__ operator. Otherwise, the result is a pointer to the object or function designated by the operand.
38+
39+
40+
## Examples
41+
42+
The following examples use these common declarations:
43+
44+
```C
45+
int *pa, x;
46+
int a[20];
47+
double d;
48+
```
49+
50+
This statement uses the address-of operator (**&**) to take the address of the sixth element of the array `a`. The result is stored in the pointer variable `pa`:
51+
52+
```C
53+
pa = &a[5];
54+
```
55+
56+
The indirection operator (__*__) is used in this example to access the `int` value at the address stored in `pa`. The value is assigned to the integer variable `x`:
57+
58+
```C
59+
x = *pa;
60+
```
61+
62+
This example demonstrates that the result of applying the indirection operator to the address of `x` is the same as `x`:
63+
64+
```C
65+
assert( x == *&x );
66+
```
67+
68+
This example shows equivalent ways of declaring a pointer to a function:
69+
70+
```C
71+
int roundup( void ); /* Function declaration */
72+
73+
int *proundup = roundup;
74+
int *pround = &roundup;
75+
assert( pround == proundup );
4376
```
44-
int *pa, x;
45-
int a[20];
46-
double d;
47-
```
48-
49-
This statement uses the address-of operator:
50-
51-
```
52-
pa = &a[5];
53-
```
54-
55-
The address-of operator (**&**) takes the address of the sixth element of the array `a`. The result is stored in the pointer variable `pa`.
56-
57-
```
58-
x = *pa;
59-
```
60-
61-
The indirection operator (**\***) is used in this example to access the `int` value at the address stored in `pa`. The value is assigned to the integer variable `x`.
62-
63-
```
64-
if( x == *&x )
65-
printf( "True\n" );
66-
```
67-
68-
This example prints the word `True`, demonstrating that the result of applying the indirection operator to the address of `x` is the same as `x`.
69-
70-
```
71-
int roundup( void ); /* Function declaration */
72-
73-
int *proundup = roundup;
74-
int *pround = &roundup;
75-
```
76-
77-
Once the function `roundup` is declared, two pointers to `roundup` are declared and initialized. The first pointer, `proundup`, is initialized using only the name of the function, while the second, `pround`, uses the address-of operator in the initialization. The initializations are equivalent.
78-
79-
## See Also
80-
[Indirection Operator: *](../cpp/indirection-operator-star.md)
81-
[Address-of Operator: &](../cpp/address-of-operator-amp.md)
77+
78+
Once the function `roundup` is declared, two pointers to `roundup` are declared and initialized. The first pointer, `proundup`, is initialized using only the name of the function, while the second, `pround`, uses the address-of operator in the initialization. The initializations are equivalent.
79+
80+
## See also
81+
82+
[Indirection Operator: *](../cpp/indirection-operator-star.md)
83+
[Address-of Operator: &](../cpp/address-of-operator-amp.md)

0 commit comments

Comments
 (0)