param array parameter : Function parameter « Function « Visual C++ .NET






param array parameter

 

#include "stdafx.h"

using namespace System;

int Total( int a, ... array<int>^ varargs)
{
   int tot = a;
   for each ( int i in varargs)
   {
      tot += i;
   }
   return tot;
}

int main()
{
   int sum1 = Total(100, 200, 350);
   Console::WriteLine("First total: {0}", sum1);

   int sum2 = Total(1, 2, 3, 4, 5, 6, 7, 8);
   Console::WriteLine("Second total: {0}", sum2);
}

   
  








Related examples in the same category

1.Passing value struct to function
2.parameter passing
3.pass by reference
4.pass by value
5.Passing array as parameter