summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--6p21.cpp27
-rw-r--r--6p22.cpp41
-rw-r--r--6p23.cpp39
-rw-r--r--6p24.cpp20
4 files changed, 127 insertions, 0 deletions
diff --git a/6p21.cpp b/6p21.cpp
new file mode 100644
index 0000000..8b84857
--- /dev/null
+++ b/6p21.cpp
@@ -0,0 +1,27 @@
+#include <iostream>
+
+/*
+ *
+ * 6.21
+ *
+ *
+ */
+
+int islarger(int i1, const int *i2) {
+
+ if(i1 > *i2) {
+ return i1;
+ }
+
+ return *i2;
+}
+
+int main () {
+
+ int a = 101;
+ int b = 253;
+ int c = 0;
+ c = islarger(a, &b);
+ std::cout << c << std::endl;
+ return 0;
+}
diff --git a/6p22.cpp b/6p22.cpp
new file mode 100644
index 0000000..91f4bcd
--- /dev/null
+++ b/6p22.cpp
@@ -0,0 +1,41 @@
+#include <iostream>
+
+/*
+ *
+ * 6.22
+ *
+ *
+ */
+
+void SwapIntPtr(int **p1, int **p2) {
+
+ int *p1tmp = *p1;
+ *p1 = *p2;
+ *p2 = p1tmp;
+}
+
+void SwapIntPtrREF(int *&p1, int *&p2) {
+
+ int *p1tmp = p1;
+ p1 = p2;
+ p2 = p1tmp;
+}
+
+int main () {
+
+ int i1 = 10;
+ int i2 = 21;
+ int i3 = 13213;
+ int i4 = 2331;
+ int *p1 = &i1;
+ int *p2 = &i2;
+ int *p3 = &i3;
+ int *p4 = &i4;
+ std::cout << "p1 " << p1 << "\np2 " << p2 << std::endl;
+ SwapIntPtr(&p1, &p2);
+ std::cout << "p1 " << p1 << "\np2 " << p2 << std::endl;
+ std::cout << "\np3 " << p3 << "\np4 " << p4 << std::endl;
+ SwapIntPtrREF(p3, p4);
+ std::cout << "p3 " << p3 << "\np4 " << p4 << std::endl;
+ return 0;
+}
diff --git a/6p23.cpp b/6p23.cpp
new file mode 100644
index 0000000..c8e2cdc
--- /dev/null
+++ b/6p23.cpp
@@ -0,0 +1,39 @@
+#include <iostream>
+#include <iterator>
+
+/*
+ *
+ * 6.23
+ *
+ *
+ */
+
+void printint(const int i) {
+
+ std::cout << i << std::endl;
+}
+
+void print1(const int *cbeg, const int *cend) {
+
+ while(cbeg != cend) {
+ std::cout << *cbeg++ << std::endl;
+ }
+}
+
+void print2(const int arr[], const size_t size) {
+
+ for(size_t i = 0 ; i != size ; i++) {
+ std::cout << arr[i] << std::endl;
+ }
+}
+
+int main () {
+
+ int i = 0;
+ int j[2] = {0, 1};
+ printint(i);
+ printint(10);
+ print1(std::cbegin(j), std::cend(j));
+ print2(j, std::cend(j) - std::cbegin(j));
+ return 0;
+}
diff --git a/6p24.cpp b/6p24.cpp
new file mode 100644
index 0000000..23e5417
--- /dev/null
+++ b/6p24.cpp
@@ -0,0 +1,20 @@
+#include <iostream>
+
+/*
+ *
+ * 6.24
+ *
+ *
+ */
+
+int main () {
+
+ /*
+ void print(const int (&ia)[10])
+ {
+ for (size_t i = 0; i != 10; ++i)
+ cout << ia[i] << endl;
+ }
+ */
+ return 0;
+}