I want to write a function that returns the size of a quadratic matrix; i.e. for a 5x5 matrix as below in my code the function "get_table_size" should return 5. However, in the example below, "get_table_size" returns 8; but when I use the macro "SIZE", that does exaclty the same thing as the function, it returns the correct number, namely 5.
Could you please tell me what I am doing wrong?
#include <stdio.h>
#include <stdlib.h>
#define SIZE(table) ((int) (sizeof (table) / sizeof (table)[0]))
int get_table_size(char* table)
{
return (sizeof(table) / sizeof(table)[0]);
}
int main()
{
char table[5][5] =
{
{'A', 'B', 'C', 'D', 'E'},
{'F', 'G', 'H', 'I', 'J'},
{'K', 'L', 'M', 'N', 'O'},
{'P', 'Q', 'R', 'S', 'T'},
{'U', 'V', 'W', 'X', 'Y'}
};
printf("\n");
printf("%d\n", get_tableu_size(table)); // does not work
printf("%d\n", SIZE(table)); //does work
return 0;
}