I understood that when you pass the name of the array as an argument to a function we are actually passing the base address of the array, which inturn gets collected by a pointer variable and thus s[i]=(s+i)=(i+s)=i[s]. The problem begins when we turn to 2-D arrays. When we want to access a column element i.e s[i][j] in pointer notation this becomes ((s+i)+j). What is the logic for this? I understood that in memory the arrays are all 1-D arrays and 2-D arrays are nothing but array of arrays i.e. the individual rows become arrays. Based upon this understanding can someone explain the logic of using ((s+i)+j) to access 2-D array elements?

## All 3 Replies

When we want to access a column element i.e s[i][j] in pointer notation this becomes ((s+i)+j)

Not quite. Multiply i by the size of the first array dimension.

s[i][j] = s[(i*original length of first dimension) + j]

Thanx alot @Moschops...I kinda figured out my mistake....In a 2-d array the compiler assigns ADDRESSES to every ROW in the array and hence we can access a 2-d array as ((s+i)+j).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.