summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOskar <[email protected]>2024-09-05 10:45:59 +0200
committerOskar <[email protected]>2024-09-05 10:45:59 +0200
commita30d605024322ada2206d10898b8dfd6220107c1 (patch)
tree8dd65c678b42a84fb73bc2b69e222a0b53890b20
parent80b6fffdf40a04ed7fa719b038ee4d5380dd3a87 (diff)
more
-rw-r--r--6p6.cpp14
-rw-r--r--6p7.cpp30
2 files changed, 44 insertions, 0 deletions
diff --git a/6p6.cpp b/6p6.cpp
new file mode 100644
index 0000000..d8963f7
--- /dev/null
+++ b/6p6.cpp
@@ -0,0 +1,14 @@
+
+/*
+ *
+ * 6.6
+ *
+ *
+ */
+
+int main () {
+
+ // When the function ends the local variable is destroyed
+ // When the function ends the static variable retains its value and is still there when the function is called again.
+ return 0;
+}
diff --git a/6p7.cpp b/6p7.cpp
new file mode 100644
index 0000000..2c16109
--- /dev/null
+++ b/6p7.cpp
@@ -0,0 +1,30 @@
+#include <iostream>
+
+/*
+ *
+ * 6.7
+ *
+ *
+ */
+
+int ThisFunctionHasAStaticVariable() {
+
+ static int i = -1;
+ ++i;
+ return i;
+}
+
+int main () {
+
+ std::cout << ThisFunctionHasAStaticVariable() << std::endl;
+ std::cout << ThisFunctionHasAStaticVariable() << std::endl;
+ std::cout << ThisFunctionHasAStaticVariable() << std::endl;
+ std::cout << ThisFunctionHasAStaticVariable() << std::endl;
+ std::cout << ThisFunctionHasAStaticVariable() << std::endl;
+ std::cout << ThisFunctionHasAStaticVariable() << std::endl;
+ std::cout << ThisFunctionHasAStaticVariable() << std::endl;
+ std::cout << ThisFunctionHasAStaticVariable() << std::endl;
+ std::cout << ThisFunctionHasAStaticVariable() << std::endl;
+ std::cout << ThisFunctionHasAStaticVariable() << std::endl;
+ return 0;
+}