A simple method is to smooth the array and iterate using dimensions.
#include <stdio.h> void print_array(int *arr,int row,int col) { int i,j; for(i=0;i<row;i++){ for(j=0;j<col;j++){ printf("%d ",*(arr+i*col+j)); } printf("\n"); } } int main() { int a[2][3] = {{1,0,2},{-1,3,1}}; int b[4] = {1,2,3,34}; print_array(a,2,3); return 0; }
This method works, but smoothing the array can interfere with compiler optimization, which in turn can lead to slower execution.
Sandeep
source share