Ask Question

Suppose that a is declared as an int a[99]. Give the contents of the array after the following two statements are executed: for (i = 0; i <99; i++) a[i] = a[a[i]];

+2
Answers (1)
  1. 16 January, 04:16
    0
    Each array position holds the position from which the information is going to be retrieved. After the code is run, each position will have the information retrieved from that position.

    Explanation:

    The best way to solve this problem is working as if we had a very small array. Then we can generalize for the large array.

    For example

    int a[3];

    a[0] = 1; a[1] = 2; a[2] = 0;

    for (i = 0; i < 3; i++)

    a[i] = a[a[i]];

    When i = 0, we have:

    a[i] = a[a[i]] = a[a[0]] = a[1] = 2;

    When i = 1, we have

    a[i] = a[a[i]] = a[a[1]] = a[2] = 0;

    When i = 2, we have

    a[i] = a[a[i]] = a[a[2]] = a[0] = 1;

    Basically, in our small example, each array position holds the index from which we are going to retrieve the information. The same is going to happen in the array of length 99. After the code is run, each position will have the information retrieved from that position
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Suppose that a is declared as an int a[99]. Give the contents of the array after the following two statements are executed: for (i = 0; i ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers