cplusplus:pointers_3
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
cplusplus:pointers_3 [2014/04/29 20:39] – [Pointer arithmetic] mithat | cplusplus:pointers_3 [2016/03/05 23:21] – [Array arithmetic] mithat | ||
---|---|---|---|
Line 2: | Line 2: | ||
Pointers, arrays, arithmetic.((Portions loosely adapted from: FIXME)) | Pointers, arrays, arithmetic.((Portions loosely adapted from: FIXME)) | ||
+ | |||
+ | <WRAP center round important 60%> | ||
+ | This content has not been vetted for C++11 compliance. | ||
+ | </ | ||
===== Pointers and arrays ===== | ===== Pointers and arrays ===== | ||
Line 42: | Line 46: | ||
<file cpp pointer-math.cpp> | <file cpp pointer-math.cpp> | ||
+ | /** Pointer arithmetic. */ | ||
#include < | #include < | ||
using namespace std; | using namespace std; | ||
Line 66: | Line 71: | ||
<file cpp subtracting-pointers.cpp> | <file cpp subtracting-pointers.cpp> | ||
+ | /** Subtracting pointers */ | ||
#include < | #include < | ||
using namespace std; | using namespace std; | ||
Line 83: | Line 89: | ||
==== Walking down an array ==== | ==== Walking down an array ==== | ||
- | A common technique used to visit every element in an array is to //walking | + | A common technique used to visit every element in an array is to //walk down an array// with a pointer: |
<file cpp walk-down-array.cpp> | <file cpp walk-down-array.cpp> | ||
+ | /** Walking down an array. */ | ||
#include < | #include < | ||
using namespace std; | using namespace std; | ||
Line 94: | Line 101: | ||
int *vPtr = v; | int *vPtr = v; | ||
- | for(int i=0; i<5; i++) | + | for (int i = 0; i < 5; i++) |
{ | { | ||
cout << *vPtr << endl; | cout << *vPtr << endl; | ||
Line 107: | Line 114: | ||
<file cpp walk-null-terminated.cpp> | <file cpp walk-null-terminated.cpp> | ||
+ | /** Walking down a null-terminated array. */ | ||
#include < | #include < | ||
using namespace std; | using namespace std; | ||
Line 146: | Line 154: | ||
^ Operation | ^ Operation | ||
- | |< | + | |Increment |
- | |< | + | |Decrement |
- | |< | + | |Arithmetic |
- | |< | + | |Compound assignment |
valptr += 2; // points at 11</ | valptr += 2; // points at 11</ | ||
- | |< | + | |Pointer subtraction |
cplusplus/pointers_3.txt · Last modified: 2016/03/05 23:27 by mithat