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
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.