Friday, December 23, 2016

Array as Function Argument -C++

#include<iostream>
using namespace std;

void f1(int a[], int size)    //A user-defined function which takes an 'int array'  as arguments
{
  for(int i=0;i<size;i++)
 {
   cout<<a[i]<<endl;
 }

}

int main()
{
    int ar[]={1,2,3,4,5,6,7,8,9,10,11};
    f1(ar,7);    //passing array name and no. of elements(less than actual) to be displayed as args
    f1(ar,11);   //passing array name and no. of elements(equal to actual) to be displayed as args
    f1(ar,15);   //passing array name and no. of elements(more than actual) to be displayed as args
    return 0;
}

No comments:

Post a Comment

Sacred Thought

5 May 2024 Hari Om Verse 50-51, chapter two:  In this chapter two Shree krishna explains a simple way of living. Free from desires and void ...