How to pass individual elements in an array as argument to function in C language?

If individual elements are to be passed as arguments, then array elements along with their subscripts must be given in function call.

To receive the elements, simple variables are used in function definition.

Example 1

#include
main (){
   void display (int, int);
   int a[5], i;
   clrscr();
   printf (“enter 5 elements”);
   for (i=0; i

Output

Enter 5 elements
   10    20    30    40    50
First element = 10
Last element = 50

Example 2

Consider another example for passing individual elements as argument to a function.

#include
main (){
   void arguments(int,int);
   int a[10], i;
   printf ("enter 6 elements:
");    for (i=0; i",a);    printf ("last element = %d
",b); }

Output

enter 6 elements:
1
2
3
4
5
6
first element = 1
last element = 6
Updated on: 2021-03-09T08:10:07+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements