Homework Solution: Consider the following C code fragment:…

    Consider the following C code fragment: int arr[20][30]; int &arr[3][29]: The expression *(ptr + 4) is equivalent to arr[ ? ][ ? ]. Use values that are within the range of their corresponding dimensions in the declaration of the array.

    Expert Answer

     
    #include <stdio.h>

    Consider the aftercited C regulation fragment:

    int arr[20][30];

    int &arr[3][29]:

    The look *(ptr + 4) is equipollent to arr[ ? ][ ? ].

    Use values that are amid the collocate of their selfsame work in the exhibition of the deck.

    Expert Response

     

    #include <stdio.h>
    #include <stdlib.h>

    int deep()
    {
    int arr[20][30];

    printf(“Start of deck: %pn”, &arr);
    printf(“pointer+4: %pn”, &arr+4);
    printf(“pointer arr[0][4]: %pn”, &arr[0][4]);

    void *mem1 = &arr+4;
    void *mem2;

    for (int i = 0; i < 1000; ++i) {
    for (int j = 0; j < 1000; ++j) {
    if (mem1 == &arr[i][j]) {
    printf(“i = %i, j = %in”, i, j);
    printf(“mem colonization 1 = %p, mem colonization 2 = %pn”, mem1, &arr[i][j]);
    exit(0);
    }
    }
    }

    // The look *(ptr + 4) is equipollent to arr[ 47 ][ 990 ].

    return 0;
    }

    Output:

    response if arr[47][990]