-->

Parsing Array Elements to Function

Parsing Array Elements to Function
Parsing Array Elements to Function: 
Arrays are a collection of one or more elements of the same data type. Array elements can be passed to the function by the value or a reference. Programs given below explain both the ways.

Example:
Write a program to pass the array elements to the function. Use call by value method.

#include<stdio.h>
#include<conio.h>
void show(int, int)
void main()
{
Int k;
int num[]={12,13,14,15,16,17,18};
clrscr();
for(k=0;k<7;k++)
show(k, num[k]);
}
show(int m, int u)
{
printf(“\n num[%d]=%d”,m+1,u);
}

OUTPUT
Num[1]=12
Num[2]=13
Num[3]=14
Num[4]=15
Num[5]=16
Num[6]=17
Num[7]=18

Explanation:
The show() is a user defined function. The array num[] is initialized with seven elements. Using for loop the show() function is called seven times and one element is sent per call. The function show() prints the element.

Related Posts

Subscribe Our Newsletter