Passing a two-dimensional array to a function : function parameters « Function « C++ Tutorial

Home
C++ Tutorial
1.Language Basics
2.Data Types
3.Operators statements
4.Array
5.Development
6.Exceptions
7.Function
8.Structure
9.Class
10.Operator Overloading
11.Pointer
12.File Stream
13.template
14.STL Introduction
15.string
16.vector
17.list
18.bitset
19.set multiset
20.valarray
21.queue stack
22.deque
23.map multimap
24.STL Algorithms Modifying sequence operations
25.STL Algorithms Non modifying sequence operations
26.STL Algorithms Binary search
27.STL Algorithms Sorting
28.STL Algorithms Merge
29.STL Algorithms Min Max
30.STL Algorithms Iterator
31.STL Algorithms Heap
32.STL Algorithms Helper
C++ Tutorial » Function » function parameters 
7.3.14.Passing a two-dimensional array to a function
#include <iostream>
using std::cout;
using std::endl;

double f(double values[][4]int n);

int main() {
  double beans[3][4{
                         1.0,  2.0,  3.0,  4.0},
                         5.0,  6.0,  7.0,  8.0},
                         9.010.011.012.0}
                       };

  cout << f(beans, sizeof beans/sizeof beans[0])<< endl;
  return 0;
}

double f(double array[][4]int size) {
  double sum = 0.0;
  for(int i = ; i < size ; i++)       
    for(int j = ; j < ; j++)        
      sum += array[i][j];
  return sum;
}
78
7.3.function parameters
7.3.1.Passing int by value
7.3.2.Define function to accept three int parameters
7.3.3.Pass a pointer to a function.
7.3.4.Pass variable address to a function
7.3.5.Pass int array to a function
7.3.6.Declare int array parameter for a function without indicating the array length
7.3.7.Function parameter: Use int pointer to accept an array
7.3.8.Use array as function's parameter
7.3.9.Change the contents of an array using a function
7.3.10.Pass a string to a function: Invert the case of the letters within a string
7.3.11.Change a call-by-value parameter does not affect the argument
7.3.12.Demonstrate the pointer version of swap(): Exchange the values of the variables pointed to by x and y
7.3.13.Using reference parameters
7.3.14.Passing a two-dimensional array to a function
7.3.15.Passing an array to a function
7.3.16.var args has to be the last one
7.3.17.the use of ... and its support macros va_arg, va_start, and va_end
7.3.18.Handling an array parameter as a pointer
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.