In this program a pointer an array is used:
//#include <conio.h>
#include <iostream>
using namespace std;
int main()
{
int a[5] = {1,2,3,4,5};
int b[5] = {6,7,8,9,10};
int (*pa[4])[5] = {&a,&b,&a,&b};
for(int i = 0; i < 4; i++)
{
for(int j = 0; j < 5; j++)
cout<< (*pa[i])[j] << "
cout<< "\n";
}
//_getch();
cin.get();
}
In some compilers comparison of &a
and a
is allowed. For example this code can be compiled in (old) Borland compilers:
//#include <conio.h>
#include <iostream>
using namespace std;
int main()
{
int a[20];
cout<< (a == &a);
//_getch();
cin.get();
}
and the output is 1. But in previous program instead of
int (*pa[4])[5] = {&a,&b,&a,&b};
one cannot write
int (*pa[4])[5] = {a,b,a,b};