Addresses of 1d arrays are actually taken as
a[i]=*(a+i);
Are the addresses of 2d arrays calculated as
a[i][j]=**(a+i+j);
Addresses of 1d arrays are actually taken as
a[i]=*(a+i);
Are the addresses of 2d arrays calculated as
a[i][j]=**(a+i+j);
No. a and a[i] are of different types (respectively int** and int*).
Supposing that in your example a was defined as array of array of int (eg a[10][20]), when you pass it to a function (thereby converting it to pointer to the first element of the array) you have (with further "simplifications" for the 2nd array rank)
a is of type `int**`
a[i] is of type `int*`
a[i][j] is of type `int`
*(a+i) is of type `int*`
a+i+j is of type `int**`
*(a+i+j) is of type `int*`
*(*(a+i)+j) is of type `int`
a is indeed a "2d array" (by which we normally mean an array of arrays) then it decays to type int (*)[n].a is defined as a[10][20] then a is not of type int**, it's of type int(*)[20].// CTest.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
void print (int i, int j )
{
int a[3][3] = {
{ 1,2,3 },
{ 4,5,6 },
{ 7,8,9 }
};
printf ("%d\n", *(*(a+i)+j) );
printf ("%d\n", a[i][j] );
}
int _tmain(int argc, _TCHAR* argv[])
{
print (0,0);
print (1,1);
print (2,2);
return 0;
}
Returns:
1 1 5 5 9 9
*This has been run through a compiler....