This is a valid code according to c99 standard and this code-snippet is running fine on gcc compiler.
#include <stdio.h>
void foo( int n, int m, int a[][m]){
//do stuff
}
int main() {
int n,
m;
scanf("%d %d", &n, &m);
int a[n][m];
foo(n, m, a);
return 0;
}
But the equivalent C++ code is not running on g++ compiler.
#include <cstdio>
#include <iostream>
using namespace std;
void foo( int n, int m, int a[][m]){
//do stuff
}
int main() {
int n,
m;
cin >> n >> m;
int a[n][m];
foo(n, m, a);
return 0;
}
I am getting the following error.
error: use of parameter outside function body before ‘]’ token
void foo( int n, int m, int a[][m]){
I cannot find the simple solution in C++ as it available in C for this problem.