cplusplus:pointers_2
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
cplusplus:pointers_2 [2016/03/05 22:27] – [Calling functions by reference] mithat | cplusplus:pointers_2 [2019/03/11 19:53] – [Pointer to constant data] mithat | ||
---|---|---|---|
Line 3: | Line 3: | ||
Pointers and comparisons, | Pointers and comparisons, | ||
Deitel, Harvey M., and Paul J. Deitel. " | Deitel, Harvey M., and Paul J. Deitel. " | ||
- | |||
- | <WRAP center round important 60%> | ||
- | This content has not been vetted for C++11 compliance. | ||
- | </ | ||
- | |||
===== Comparing pointers ===== | ===== Comparing pointers ===== | ||
Line 28: | Line 23: | ||
<file cpp function-with-pointer.cpp> | <file cpp function-with-pointer.cpp> | ||
- | /** Demostrates | + | /** Demonstrates |
#include < | #include < | ||
using namespace std; | using namespace std; | ||
Line 93: | Line 88: | ||
</ | </ | ||
- | <WRAP center | + | <WRAP center tip 90%> |
- | I (and many other programmers) | + | I feel pointers are much better |
</ | </ | ||
===== 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 135: | ||
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 144: | ||
myPtr = & | myPtr = & | ||
</ | </ | ||
+ | |||
+ | |||
+ | <WRAP center tip 90%> | ||
+ | One way to remember this is //"'' | ||
+ | |||
+ | In the case of: | ||
+ | <code c++>int *const myPtr = & | ||
+ | '' | ||
+ | |||
+ | In the case of: | ||
+ | <code c++> | ||
+ | '' | ||
+ | </ | ||
==== Constant pointer to constant data ==== | ==== Constant pointer to constant data ==== | ||
Line 161: | Line 169: | ||
myPtr = & | myPtr = & | ||
</ | </ | ||
- | |||
- | |||
- | |||
cplusplus/pointers_2.txt · Last modified: 2019/03/28 16:55 by mithat