Two-dimensional arrays are used in C language
1#include <iostream>2#include <stdlib.h>3 using namespacestd;4 5 voidPRINT_ARR_FUN1 (intarr[][3],introw) {6 for(inti =0; i < row; ++i) {7 for(intj =0; J <3; ++j)8cout << Arr[i][j] <<" ";9cout <<Endl;Ten } One } A - voidPrint_arr_fun2 (int*arr,intRowintCol) { - for(inti =0; i < row; ++i) { the for(intj =0; J < Col; ++j) -cout << * (arr + i * row + j) <<" "; -cout <<Endl; - } + } - + voidPRINT_ARR_FUN3 (int**arr,intRowintCol) { A for(inti =0; i < row; ++i) { at for(intj =0; J < Col; ++j) -cout << Arr[i][j] <<" "; -cout <<Endl; - } - } - in intMain () { - Const introw =2;//here is the const to Const intCol =3; + intArr1[row][col]; - for(inti =0; i < row; ++i) the for(intj =0; J < Col; ++j) *ARR1[I][J] = i * col +J; $ Panax Notoginsengcout <<"print_arr_fun1---------------------------"<<Endl; - print_arr_fun1 (arr1, row); thecout <<"print_arr_fun2---------------------------"<<Endl; +Print_arr_fun2 ((int*) arr1, Row, col); A thecout <<"Print_arr_fun3---------------------------"<<Endl; + int**ARR2 = (int**)malloc(sizeof(int*) *row); - //malloc $ for(inti =0; i < row; ++i) $Arr2[i] = (int*)malloc(sizeof(int) *col); - for(inti =0; i < row; ++i) - for(intj =0; J < Col; ++j) theARR2[I][J] = i * col +J; - print_arr_fun3 (arr2, Row, col);Wuyi the // Free - for(inti =0; i < row; ++i) Wu Free(Arr2[i]); - Free(ARR2); About $ return 0; -}
Output:
b/C + + two-dimensional arrays