83.4k views
2 votes
Which of the following is NOT a valid method to increase a variable named score by 1?

a.
++score = score + 1

b.
score = score + 1

c.
score++

d.
++score

User Smolda
by
5.5k points

1 Answer

4 votes

Answer:

a.

++score = score + 1

Step-by-step explanation:

First you have to understand the increment operator;

There are three possible ways to increment the value of variable by 1.

1. post increment

syntax:

name++

it using in expression first then increase the value by 1.

2. Pre increment

syntax:

++name

it increase the value by 1 before it using in expression.

3. simple method

name = name +1

In the question,

option 1: ++score = score + 1

it increase the value of score by 2 because their are two increment is used first for (score + 1) and second ++score.

Therefore, the correct option is a.

User Kevin Gorjan
by
5.7k points