lundi 30 mai 2016

Explain the output of this loop

This is a question from a past paper that I am having issues with, the question and output is displayed below but I don't understand how this is achieved. Can someone please explain.

int main ()
{
    int a[5] = { 1 }, b[] = { 3, -1, 2, 0, 4 };
    for (int i = 0; i<5; i++)
    {
        if (!(a[i] = b[i])) // note: = not ==
            break;
        cout << a[i] << endl;
    }
}

Output:

 3
-1
 2

Aucun commentaire:

Enregistrer un commentaire