I have searched but could not find the appropriate solution. The code generates a 2D array in a function by taking size of the array as the arguments. Now in main() function, I want the array to be printed. But the output is not correct. This is what I have got so far.
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
int * generate(int size){
    int i, j;
    // allocate  memory
    static int **X = (int **)malloc(size * sizeof(int *)); 
    for(i=0; i<size;i++)
        X[i]=(int *)malloc(size * sizeof(int));
    
    for(i=0; i<size;i++)
        for(j=0;j<size;j++)
            X[i][j]=rand()%1000;
    
    return *X;
}
int main(){
    srand(time(NULL));
    int size=3;
    int *p=generate(size);
    
    for(int i=0; i<size; i++){
        for(int j=0; j<size;j++){
            printf("%5d ",(*(p+i)+j));
        }
        printf("\n");
    }
    return 0;
}
 
     
    