I was trying to initialize and print array of pointers to integers. Is this method of initialization is correct or any other method is available to initialize when we declare it as array of pointers. We can also use traditional array of arrays ar1[][] anyway.
#include <stdio.h>
#include <stdlib.h>
#define NUM_COLS 4
#define NUM_ROWS 3
int main(void)
{
int rowCnt;
int colCnt;
int *ar2[NUM_ROWS]={
(int[]){11,12,13,14},
(int[]){21,22,23,24},
(int[]){31,32,33,34},
};
for(rowCnt=0;rowCnt<NUM_ROWS;rowCnt++)
{
for(colCnt=0;colCnt<NUM_COLS;colCnt++)
{
printf("%d\t",*(*(ar2+rowCnt)+colCnt));
}
printf("\n");
}
return(0);
}