Home >Backend Development >C++ >How to pass entire array as parameter to function in C language?
An array is a group of related items with the same name. Here are two ways to pass an array as an argument to a function:
To pass an entire array as a parameter, simply send the array name in the function call.
To receive an array, it must be declared in the function header.
#include<stdio.h> main (){ void display (int a[5]); int a[5], i; clrscr(); printf ("enter 5 elements"); for (i=0; i<5; i++) scanf("%d", &a[i]); display (a); //calling array getch( ); } void display (int a[5]){ int i; printf ("elements of the array are"); for (i=0; i<5; i++) printf("%d ", a[i]); }
Enter 5 elements 10 20 30 40 50 Elements of the array are 10 20 30 40 50
Let us consider another example to understand about More information on passing an entire array as a parameter to a function -
#include<stdio.h> main (){ void number(int a[5]); int a[5], i; printf ("enter 5 elements</p><p>"); for (i=0; i<5; i++) scanf("%d", &a[i]); number(a); //calling array getch( ); } void number(int a[5]){ int i; printf ("elements of the array are</p><p>"); for (i=0; i<5; i++) printf("%d</p><p>" , a[i]); }
enter 5 elements 100 200 300 400 500 elements of the array are 100 200 300 400 500
The above is the detailed content of How to pass entire array as parameter to function in C language?. For more information, please follow other related articles on the PHP Chinese website!