for C++, I am trying to create a function that prints a 2D array. Can you instruct me on the easiest way to do so? Please do not make it complicated, we have no started learning about pointers yet, either, so it can't be done that way.
Please find the code below:
main.cpp
#include <iostream>
using namespace std;
void printTwoDArray(int array[][4]){
cout<<"Content of array is as
below"<<endl;
for(int i=0;i<4;i++){
for(int j=0;j<4;j++){
cout<<array[i][j]<<" ";
}
cout<<endl;
}
}
int main(){
int array[4][4] =
{{1,2,3,4},{4,5,4,5},{6,6,6,6},{7,7,7,7}};
printTwoDArray(array);
return 0;
}
output:
Get Answers For Free
Most questions answered within 1 hours.