I have a segmentationfault at the line :
cout << b[0][0];
Could someone tell me what should I do to fix my code?
#include <iostream>
using namespace std;
int** gettab(int tab[][2]){
return (int**)tab;
}
int main() {
int a[4][2] = {{0, 0}, {1, 0}, {2, 0}, {2, 1}};
int ** b = gettab(a);
cout << b[0][0];
return 0;
}
A 2-dimensional array is not the same thing as an array of pointers, which is how
int**is interpreted. Change the return type of gettab.Or: