summaryrefslogtreecommitdiff
path: root/reference/C/EXAMPLES/pointer2_func.c
diff options
context:
space:
mode:
Diffstat (limited to 'reference/C/EXAMPLES/pointer2_func.c')
-rw-r--r--reference/C/EXAMPLES/pointer2_func.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/reference/C/EXAMPLES/pointer2_func.c b/reference/C/EXAMPLES/pointer2_func.c
new file mode 100644
index 0000000..19ca3d2
--- /dev/null
+++ b/reference/C/EXAMPLES/pointer2_func.c
@@ -0,0 +1,51 @@
+/*
+ * Purpose: Program to demonstrate passing an int array to a function.
+ * Author: M J Leslie.
+ * Date: 14-Apr-94
+ */
+
+void add(int swap[3][2]); /* Function declaration */
+void display(int array[3][2]); /* Function declaration */
+
+main()
+{
+ int i[3][2]=
+ {
+ {1,2}, /* array declaration */
+ {3,4},
+ {5,6}
+ };
+
+ display(i); /* i is a pointer */
+
+ add(i);
+
+ display(i);
+}
+
+/***************************************************************/
+
+void add(int swap[3][2]) /* Function definition */
+{
+ int temp,i;
+
+ for (i=0; i<3; i++)
+ {
+ temp = swap[i][0];
+ swap[i][0] = swap[i][1];
+ swap[i][1] = temp;
+ }
+ return;
+}
+
+/***************************************************************/
+
+void display(int array[3][2]) /* Function definition */
+{
+ int count=0,count1=0;
+
+ for (count=0;count<3;count++)
+ for (count1=0;count1<2;count1++)
+ printf("%d ", array[count][count1]);
+ puts("");
+}