0

So the professor wrote this as a part of showing us a way to arrange arrays. But I don't even understand how he filled the array.

    #include <iostream>

using namespace std;
int main()
{
    int n; cout << "\n\nLenght of the array??"; cin >> n;
    int* a = new int[n];
    cout << "\nStarting array:\n\n";
    for (int i = 0; i < n; i++)
        cout << (a[i] = (int)(rand() / (RAND_MAX + 1.) * 10)) << ((i % 30 == 29 || i == n - 1) ? '\n' : ' ');

}

I think it should fill the array with random numbers, but when i wrote it i got the same exact array as the professor did (0 5 1 8 5 4 3 8 8 7) so I'm even more confused. If someone could explain what is happening in for loop I would greatly appreciate it!!

0 Answers0