I have a simple setup as follows (you can also test it here: http://cpp.sh/3yxqj):
// Example program
#include <iostream>
#include <string>
void a (const char c[][2])
{
std::cout << "func c: " << (sizeof(c)/sizeof(c[0])) << std::endl;
}
int main()
{
const char c[][2] = {
{1,2},
{3,4},
{5,6},
{7,8},
{9,10},
{11,12},
};
std::cout << "main c: " << (sizeof(c)/sizeof(c[0])) << std::endl;
a(c);
return 0;
}
The output is:
main c: 6
func c: 4
Where of course 6 is correct and 4 is not. I think I understand why this is happening. The array [][] degenerates (forgive this term) into a pointer (*)[] inside the function. I don't know how to solve this problem though. I need to be able to count rows in multidimensional array after passing it into a function. Can someone please help?