c++ - typedef and multi-dimensional array -
#include <iostream> using namespace std; typedef int array[2]; int sum(array a[], int n) { int sum = 0; for(int = 0; < 2; i++) for(int j = 0; j < n; j++) sum += a[i][j]; return sum; } int main() { int n = 2, sum; array a[n]; for(int = 0; < 2; i++) for(int j = 0; j < n; j++) a[i][j] = * n + j; cout << sum(a, n) << endl; return 0; }
it use typedef in global scope? use typedef declare multi-dimensional array, instead of a[][]?
wiki
Comments
Post a Comment