2D array and pointer in C - how to access elements?

前端 未结 5 1338
小蘑菇
小蘑菇 2020-12-15 11:44

I have an example involving a pointer to a 2D array. Can someone help me understand what is going on in this example?

int main()
{

    int i = 0, j=0, sum0         


        
5条回答
  •  粉色の甜心
    2020-12-15 12:40

    In your example the loop goes through all matrix rows to find the one whose sum of all elements holds the maximum value.

    At the beginning a pointer to the first row is assigned:

    Ptr = *data;
    

    Which means that the following is true:

    (Ptr[0] == 23 && Ptr[1] == 55 && Ptr[2] == 50)
    

    Notice that Ptr is a pointer so it holds a memory address, hence Ptr is different than 23 (unless the memory address happens to be 23, which is unlikely to happen).

提交回复
热议问题