In C
void foo(int size ,int a[][size])
{
printf("%d\n", a[0][0]);
}
int main(int argc, char const *argv[])
{
int a[5][5] = {0};
foo(5, a);
return 0;
}
works fine
But the same in C++
void foo(int size, int a[][size])
{
cout << a[0][0] << endl;
}
int main(int argc, char const *argv[])
{
int a[5][5] = {0};
foo(5, a);
return 0;
}
doesnt work. It gives two errors:
error: use of parameter ‘size’ outside function body
In function ‘void foo(...)’:
error: ‘a’ was not declared in this scope
Can anyone explain why this happens. Please also explain any compiler dependent issues either in C or C++..