
Zachary A. answered 08/08/20
A passionate computer science tutor with industry experience!
For the first, the increment operator performs the increase in value to the right side after the assignment occurs. In other words, aa++ returns the prior value of aa (5) and then "increments" the temporary variable storing aa on the right side. Hence, logging aa prints out 5, as that is the value assigned.
For the second, however, you add i++ to ++i; i++ returns 1, rather than 2, as the post-increment operator returns the prior value. However, the actual value of i is now 2, hence the pre-increment operator returns 3. Adding 1 to 3 gives 4, which is the value used for to index aaa, returning 6. The for loop has k loop from 0 – 3—hence, the output is 6 7 1 4.
And, for the last one, i++ (as mentioned above) increments after the statement, but the statement is checked to start. So, i's prior value (0) is checked as being less than 5, then incremented (1), which occurs until i's prior value is greater than or equal to 5. So, 1 2 3 4 5 is printed out.
Sarah P.
Thank You!08/08/20