Good afternoon,
I'm doing some code to study more about memory allocation in C with the malloc function, and I was developing a code to allocate an array and then read values and save it, but it is giving error while executing and closing the program , someone could help me and explain why the error.
Code Snippet:
#include<stdio.h>
#include<stdlib.h>
int ** alocar(){
int ** matriz;
int i;
matriz = (int **) malloc(3 * sizeof(int *));
for(i = 0; i < 3; i++)
matriz[i] = (int *) malloc(3 * sizeof(int));
return (&matriz);
}
void lerValores(int ** matriz){
int i, j;
for(i = 0; i < 3; i++){
for(j = 0; j < 3; j++){
printf("Valor[%d][%d]:", i, j);
scanf("%d", &matriz[i][j]);
printf("\n");
}
}
}
void main()
{
int ** matriz;
matriz = alocar();
lerValores(matriz);
}