Array

Write your question here.

1
2
3
4
5
6
7
8
     #include <iostream>
   using namespace std;
   int main()
   {
       int a[2][4] = {3, 6, 9, 12, 15, 18, 21, 24};
       cout << *(a[1] + 2) << *(*(a + 1) + 2) << 2[1[a]];// 2[1[a]]
       return 0;
   }

the output of the above program is 21 21 21

QUESTION : how compiler resolves statement2[1[a]]?
It's just an obscure way of accessing array elements, I've never seen anyone use it in real code. A trick I use is to read it backwards, so this is the same as a[1][2] which gives you the 7th element in the array, '21'.
Last edited on
Record 1[a] and a[1] are equivalent and in turn are equivalent to as *(a + 1). The type of the expression is int [4] . The value of the expression is the second "row" of array a. Let assume that thsi row has name b. Then 2[b] is equivalent to *( b + 2 ) and will give the third alement in this second row that is 21.
Last edited on
thanks guys...
Topic archived. No new replies allowed.