I couldn't find it online, so I thought I should ask here. Will
arr[0]++;
behave the same as
arr[0] = arr[0] + 1;
?
For an integer it will.
But it depends on the type of arr.
In general, with an array of object or number, it will call the post-increment operator, which can be different from a regular pre-increment operator--although post-increment may appear to just increment alone, in reality, it will increment the actual object BUT it will return a copy of the unincremented object. Beware of this small technicality.
Also, note that user-defined operator overloads may not follow these semantics at all.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With