Difference between [i] + 1 and [i + 1]

Asked

Viewed 104 times

4

I have doubts about [i] + 1 and [i + 1], one increases position and the other content, correct?

In relation to rating (*i)++, it is similar to which of the two cited above?

1 answer

6

I have doubts about [i] + 1 and [i + 1], one increases position and the other content, correct?

Actually the first, the [i] +1, returns what is at the summed position of 1.

Whereas the second, the [i + 1], returns the sum position of 1.

None of them actually increases the value unless you make an assignment in the same statement, thus:

arr[i] = arr[i] + 1

So it would not be correct to say that it increases.

In relation to rating (*i)++, it is similar to which of the two cited above?

None because you are using the increment operator ++ and so it would be equivalent to doing [i]++.

Equivalent to that of [i] +1 would be *i + 1, and equivalent to [i + 1] would be *(i+1).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.