blob: 346b82e83b2de7340c047066eb0fba73a8e8aa99 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
#include <iostream>
/*
*
* 4.32
*
* We have a pointer thats basically like a begin() iterator
* We have ix that starts at 0
* We keep looping as long as ix is not equal to the size
* We keep looping as long as ptr does not point to one past the last element in ia
* This ensures that we can safely do stuff to the array inside the loop
*/
int main () {
constexpr int size = 5;
int ia[size] = {1,2,3,4,5};
for (int *ptr = ia, ix = 0 ; ix != size && ptr != ia+size ; ++ix, ++ptr){
/* . . . */
}
return 0;
}
|