I created a 2D array, and made a pointer to point to the first element. I'm trying to print the 2D array, using the pointer but I'm getting the following error. Not sure what I'm doing wrong here.
source_file.cpp: In function ‘int main()’: source_file.cpp:15:27: error: invalid types ‘char[int]’ for array subscript cout << pname[x][y] << endl;
^
#include <iostream>
#include <string>
using namespace std;
int main()
{
char name[2][2] = {'E', 'f', 'g', 'r'};
char* pname = &name[0][0];
for (int x = 0; x<2; x++)
{
for (int y = 0; y<2; y++)
{
cout << pname[x][y] << endl;
}
}
}