Returning the 2D array from function in C11

Viewed 35

I am trying to pass the input array to the main() function, but the array is still empty after executing the enter_array() function.

I get the message "Process finished with exit code -1073741819 (0xC0000005)"

Could someone please explain to me, what should I correct in order to be able to read this newly created array in main()? Here's my code:

#include <stdio.h>

int** enter_array(){
    int a[2][2];
    int row_id = 0;
    int element_id = 0;
    while (row_id<2){
        while (element_id<2){
            printf("Element number %d in row number %d:",element_id,row_id);
            scanf("%d", &a[row_id][element_id]);
            element_id++;
        }
        row_id++;
        element_id = 0;}
    return a;
}
int main() {
    int **a;
    a = enter_array();
    int row_id = 0;
    int element_id = 0;
    while (row_id<2){
        while (element_id<2){
            printf("%d", a[row_id][element_id]);
            element_id++;}
        row_id++;
        element_id = 0;
        printf("\n");}
    return 0;
}
0 Answers
Related