cplusplus:pointers_2
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | Next revisionBoth sides next revision | ||
cplusplus:pointers_2 [2016/03/05 22:35] – [Constant pointer to constant data] mithat | cplusplus:pointers_2 [2016/03/05 22:38] – mithat | ||
---|---|---|---|
Line 99: | Line 99: | ||
===== The const qualifier and pointers ===== | ===== The const qualifier and pointers ===== | ||
- | You are already familiar with C++'s '' | + | You are already familiar with C++'s '' |
* '' | * '' | ||
Line 140: | Line 140: | ||
You can also create a pointer that is itself not constant (i.e., it can be reassigned or can change "what is being pointed to") but that cannot change the value of "what is being pointed to." This is a **pointer to constant data** or simply **pointer to constant**. | You can also create a pointer that is itself not constant (i.e., it can be reassigned or can change "what is being pointed to") but that cannot change the value of "what is being pointed to." This is a **pointer to constant data** or simply **pointer to constant**. | ||
- | To create a pointer to constant, use the '' | + | To create a pointer to constant |
<code cpp> | <code cpp> | ||
Line 149: | Line 149: | ||
myPtr = & | myPtr = & | ||
</ | </ | ||
+ | |||
+ | |||
+ | <WRAP center round tip 90%> | ||
+ | One way to remember this is "const modifies the thing immediately following it." In the case of: | ||
+ | <code c++>int *const myPtr = & | ||
+ | '' | ||
+ | <code c++> | ||
+ | '' | ||
+ | </ | ||
==== Constant pointer to constant data ==== | ==== Constant pointer to constant data ==== | ||
Line 161: | Line 170: | ||
myPtr = & | myPtr = & | ||
</ | </ | ||
- | |||
- | <WRAP center round tip 90%> | ||
- | One way to remember this is "const modifies the thing immediately following it." In the case of <code c++>int *const myPtr = & | ||
- | </ | ||
cplusplus/pointers_2.txt · Last modified: 2019/03/28 16:55 by mithat