S
You can move the index, though it's gonna be a little... in general, not the most direct way.In C+++, it is easier to use a reference:int m[5][5] =
{
{ 1,2,3,4,5},
{ 6,7,8,9,10},
{ 11,12,13,14,15},
{ 16,17,18,19,20},
{ 21,22,23,24,25}
};
typedef int reduced_matrix[4][5];
reduced_matrix& r = (reduced_matrix)(m+1);
for(int i = 0; i < 4; ++i)
{
for(int j = 0; j < 5; ++j)
{
cout << r[i][j] << " ";
}
cout << endl;
}
(Programme text - https://ideone.com/cPPfP9 . But why don't you use the same dynamic body, or even better, vectors? So you'll get a more flexible solution.In the C case, I couldn't just replace the matrix, I had to use the extra level of indirectness--typedef int reduced_matrix[4][5];
reduced_matrix * r = (reduced_matrix*)(m+1);
for(int i = 0; i < 4; ++i)
{
for(int j = 0; j < 5; ++j)
{
printf("%2d ",(*r)[i][j]);
}
puts("");
}
However, there is no problem in transferring such a shifted matrix into a function:void out_matrix(int r[4][5])
{
for(int i = 0; i < 4; ++i)
{
for(int j = 0; j < 5; ++j)
{
printf("%2d ",r[i][j]);
}
puts("");
}
}
...
out_matrix(m+1);
(Comtal code https://ideone.com/EXbQ9J .