OMG! That's horrible! Just because it compiles as C++ code doesn't mean you should use it. The reason the C++ compiler supports it is for backwards compatibility agains old C code.
#include <stdlib.h> // Don't use these in C++, use <cstdlib>
#include <stdio.h> // <cstdio>
#define MAXRIX_SIZE 5 // Don't use macro, use const int
typedefchar (*Matrix)[MAXRIX_SIZE][MAXRIX_SIZE]; // Pointer to an array? Ugly!
Matrix getmartix()
{
Matrix mat; // Uninitialized pointer
printf("\n %d",sizeof(*mat)); // C
mat =(Matrix)calloc(1,sizeof *mat); // Don't use calloc, use new/delete
printf("\n In Function"); // Why \n at start instead of end?
for (int i=0;i<MAXRIX_SIZE;i++)
{
for (int j=0;j<MAXRIX_SIZE;j++)
{
(*mat)[i][j] = i+j; // Cryptical syntax, hard to read
printf("\n %d",(*mat)[i][j]);
}
}; // Don't put semicolon here
return mat; // Return pointer to allocated memory resource, who owns it?
}
int main()
{
Matrix mm; // Uninitialized pointer
mm = getmartix();
printf("\n In Main");
for (int i=0;i<MAXRIX_SIZE;i++)
{
for (int j=0;j<MAXRIX_SIZE;j++)
{
printf("\n %d",(*mm)[i][j]);
}
}; // Don't put semicolon here
getchar();
return 0; // MEMORY LEAK!
}
If you really need to return a two dimentional matrix, the way to do it in C++ it to make some kind of wrapper class, and either implement copy operations, or make it impossible to copy, and return a pointer wrapped in an auto_ptr, like this: