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);}OUTPUTNum[1]=12Num[2]=13Num[3]=14Num[4]=15Num[5]=16Num[6]=17Num[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.
Social Plugin