Expands the values of n elements in the array by 5 times times, requiring the array name as a parameter.

Source: Internet
Author: User
Tags function prototype

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.