207k views
1 vote
Which expression adds 1 to the element of array arrayName at index i, assuming the array is of type int? A. ++arrayName[ i ] B. arrayName++[ i ] C. arrayName[ i++ ] D. None of the above

User Riddell
by
5.2k points

1 Answer

4 votes

Answer:

A. ++arrayName[i]

Step-by-step explanation:

In order to add 1 to the element of an array at the given index, we can use increment operators - ++ sign. This operator can be placed either before the variable name or after the variable name. Note that since we deal with an array in this situation, the index of the array needs to be specified.

In option A, pre-increment operator is used to increment value of arrayName variable at index i, ++arrayName[i]

User JeroenW
by
5.1k points