Valid C ++ operator?

I could not find it on the Internet, so I thought I should ask here. Will it

arr[0]++;

behave the same way

arr[0] = arr[0] + 1;

?

+4
source share
2 answers

For an integer it will be.

But it depends on the type of arr .

+10
source

In this case, yes. But in other situations, no, it won’t.

In general, with an array of an object or a number, it will call the post-increment operator, which may differ from the usual pre-increment operator - although the post-increment may seem to simply increase alone, it will increase the actual object, but it will return a copy of the non-incremental object. Beware of this small technical point.

, .

+1

All Articles