passing - /* attempt to add one to l and to each element of...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
/* passing.c * Demonstration of the different behaviour observed when an integer * variable is passed to a function, compared with when an array is * passed to a function. */ #include <stdio.h> #define N 1 void add_one(int m, int arr[]); int main() { int i; int l = 0; /* declare and define integer l */ int array[N]; /* declare array */ /* define array */ for (i = 0; i < N; i++) array[i] = 0.0;
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: /* attempt to add one to l and to each element of the array */ add_one(l, array); /* did it work? */ printf(&quot;l=%d\n&quot;, l); for (i = 0; i &lt; N; i++) printf(&quot;array[%d] = %d\n&quot;, i, array[i]); return 0; } void add_one(int m, int arr) { /* add one to input integer and each element of input array */ int i; m = m+1; for(i = 0; i &lt; N; i++) arr[i] = arr[i] + 1; return; }...
View Full Document

Ask a homework question - tutors are online