by passing the array name as a parameter, you are actually passing the address of the array to the formal parameter. This allows the entire array to be manipulated in the called function, passing the array name as a parameter, both the calling function and the called function acting on the array that occupies the same piece of memory unit.
#include <stdio.h> #define N 10void MulArray1 (int *x,int n);//array name as the function prototype of the parameter void MulArray2 (int *aptr,int n);// The function prototype of the pointer as a parameter is void main () {int a[n]={1,2,3,4,5,6,7,8,9,10};int i;printf ("The element of the original array is: \ n"); for (i=0;i<n;i++) printf ("%4d ", A[i]);p rintf (" \ n ");p rintf (" The array element is magnified 5 times times after the first time: \ n "); MulArray1 (a,n);//Call the array name as a function of the parameter for (i=0;i<n;i++) printf ("%4d", A[i]); printf ("\ n"); printf ("The array element is magnified 5 times times after the second time: \ n"); MulArray2 (a,n);//call pointer as parameter of function for (i=0;i<n;i++) printf ("%4d", A[i]); printf ("\ n");} void MulArray1 (int b[],int n) {int i;for (i=0;i<n;i++) b[i]=b[i]*5;} void MulArray2 (int *aptr,int n) {int i;for (i=0;i<n;i++) * (aptr+i) =* (aptr+i);
Operation Result:
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Expands the values of n elements in the array by 5 times times, requiring the array name as a parameter.