summaryrefslogtreecommitdiff
path: root/reference/C/EXAMPLES/const2.c
diff options
context:
space:
mode:
Diffstat (limited to 'reference/C/EXAMPLES/const2.c')
-rw-r--r--reference/C/EXAMPLES/const2.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/reference/C/EXAMPLES/const2.c b/reference/C/EXAMPLES/const2.c
new file mode 100644
index 0000000..249a071
--- /dev/null
+++ b/reference/C/EXAMPLES/const2.c
@@ -0,0 +1,33 @@
+/*******************************************************************
+ *
+ * Purpose: 'const' example. This code shows that making a
+ * variable 'const' only tells the compiler to not
+ * allow reassignment of the variable. The data is not
+ * in a special location, it can still be altered.
+ *
+ * This code may cause compiler warning messages
+ * but will compile and run.
+ *
+ * Author: M J Leslie.
+ * Date: 03-Mar-97
+ *
+ *******************************************************************/
+
+main()
+{
+ const int Men = 10;
+ int *Women = &Men;
+
+ *Women = 20;
+
+ printf("There are %d men\n", Men);
+
+}
+
+/*******************************************************************
+ *
+ * Result.
+ *
+ * There are 20 men
+ *
+ *******************************************************************/