in my program, i've taken the input from user, passed the 2 input matrices to the addtn function which performs addition, but the function is not returning the correct values to main,it is actually returning garbage values Mainly, i want to learn how to return a 2d array to the main module This is main module Code: #include<stdio.h> #include<conio.h> void input(int (*in)[3]); int *addtn(int (*x)[3],int (*y)[3]); void main() { int mat1[3][3],mat2[3][3],choice; int i,j,(*res)[3]; clrscr(); printf("\nEnter the elements of first matrix:\n"); input(mat1); printf("\nEnter the elements of second matrix:\n"); input(mat2); do { clrscr(); printf("\t\t\t 1) ADDITION\n"); printf("\t\t\t 2) EXIT\n\n\n"); printf("\n\nEnter Your choice: "); scanf("%d",&choice); switch(choice) { case 1: res=addtn(mat1,mat2); for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf("%d\t",*(*(res+i)+j)); } } getch(); break; case 2: exit(1); default : printf("Not in the list of choices. Enter from the list only!"); } }while(1); } This is for input Code: //********************************INPUT************************** void input(int (*in)[3]) { int i,j; for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf("\nEnter the Element of row,%d and col,%d: ",i+1,j+1); scanf("%d",(*(in+i)+j)); } } getch(); clrscr(); } For addition, the problem area, which is not returning correctly Code: int *addtn(int (*x)[3],int (*y)[3]) { int i,j,c[3][3]; for(i=0;i<3;i++) for(j=0;j<3;j++) c[i][j]=0; for(i=0;i<3;i++) { for(j=0;j<3;j++) { c[i][j]= *(*(x+i)+j)+ *(*(y+i)+j); //performing addition here } } getch(); clrscr(); return(c); //returning here }
Can you please give me the warning/error message if you get? If no such, have you tried to print that array?