Skip to content

Commit

Permalink
Update ex3_44.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Mooophy committed Jun 21, 2015
1 parent a24d68f commit fd6e36d
Showing 1 changed file with 24 additions and 25 deletions.
49 changes: 24 additions & 25 deletions ch03/ex3_44.cpp
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
#include <iostream>

using std::cout; using std::endl;

int main()
{
int ia[3][4] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
// a range for to manage the iteration
// use type alias
using int_array = int[4];
for (int_array& p : ia)
for (int q : p)
cout << q << " ";
cout << endl;
// ordinary for loop using subscripts
for (size_t i = 0; i != 3; ++i)
for (size_t j = 0; j != 4; ++j)
cout << ia[i][j] << " ";
cout << endl;
// using pointers.
// use type alias
for (int_array* p= ia; p != ia + 3; ++p)
for (int *q = *p; q != *p + 4; ++q)
cout << *q << " ";
cout << endl;
return 0;
int ia[3][4] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };

// a range for to manage the iteration
// use type alias
using int_array = int[4];
for (int_array& p : ia)
for (int q : p)
cout << q << " ";
cout << endl;

// ordinary for loop using subscripts
for (size_t i = 0; i != 3; ++i)
for (size_t j = 0; j != 4; ++j)
cout << ia[i][j] << " ";
cout << endl;

// using pointers.
// use type alias
for (int_array* p = ia; p != ia + 3; ++p)
for (int *q = *p; q != *p + 4; ++q)
cout << *q << " ";
cout << endl;

return 0;
}

0 comments on commit fd6e36d

Please sign in to comment.