ccplusplus.com
Learn C, C++ Concepts
Sunday, April 8, 2012
2d array as function parameter c++
/******************************************************************* * File : passing_2d_array_to_function_as_argument.cpp * Author : Team ccplusplus * Description : 2d array as function parameter c++ * Date : AM 01:13 07 April 2012 * Source : http://www.ccplusplus.com/p/c_15.html * Note : *******************************************************************/ #include
using namespace std; double sum(double array[][3], int size) { double temp = 0.0; for(int i = 0 ; i < size ; i++) { for(int j = 0 ; j < 3 ; j++) { temp += array[i][j]; } } return temp; } int main() { double array[2][3] = { { 1.0, 2.0, 3.0}, { 5.0, 6.0, 7.0} }; cout << "Sum of all the elements in array[2][3] is: "<< sum(array, sizeof array/sizeof array[0])<< endl; return 0; } /* * * [blog@ccplusplus multidimensional_arrays_2D_3D_nD]$ c++ passing_2d_array_to_function_as_argument.cpp -o passing_2d_array_to_function_as_argument [blog@ccplusplus multidimensional_arrays_2D_3D_nD]$ ./passing_2d_array_to_function_as_argument Sum of all the elements in array[2][3] is: 24 [blog@ccplusplus multidimensional_arrays_2D_3D_nD]$ */
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment