forked from pezy/CppPrimer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex6_23.cpp
53 lines (44 loc) · 972 Bytes
/
ex6_23.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Write your own versions of each of the print functions
// presented in this section. Call each of these functions to print i and j
// defined as follows:
// int i = 0, j[2] = {0, 1};
#include <iostream>
using std::begin;
using std::cout;
using std::end;
using std::endl;
void print(int* const pi)
{
if (pi) cout << *pi << endl;
}
void print(const char* p)
{
if (p)
while (*p) cout << *p++;
cout << endl;
}
void print(const int* beg, const int* end)
{
while (beg != end) cout << *beg++ << " ";
cout << endl;
}
void print(const int ia[], size_t size)
{
for (size_t i = 0; i != size; ++i) cout << ia[i] << " ";
cout << endl;
}
void print(const int (&arr)[2])
{
for (auto i : arr) cout << i << " ";
cout << endl;
}
int main()
{
int i = 0, j[2] = {0, 1};
char ch[5] = "pezy";
print(ch);
print(begin(j), end(j));
print(&i);
print(j, end(j) - begin(j));
print(const_cast<const int(&)[2]>(j));
}