154k views
2 votes
Assume that the variable count has been declared as type int. Which statement adds 10 to count?

a) count = 10;
b) count == count + 10;
c) count = count + 10;
d) count + 10;

1 Answer

2 votes

Final answer:

The correct statement to add 10 to the variable count declared as type int is "c) count = count + 10;" which assigns the new value back to count, increasing it by 10.

Step-by-step explanation:

To add 10 to the variable count which is declared as type int, the correct statement to use is "c) count = count + 10;". Here is a breakdown of why the other choices are incorrect:

  • a) count = 10; - This line will set the value of count to 10, rather than adding 10 to the current value.
  • b) count == count + 10; - This line uses a comparison operator (==) instead of an assignment operator (=), so it compares two values rather than assigning a new value to count.
  • d) count + 10; - This expression adds 10 to count, but it does not assign the new value back to count, so the original value of count remains unchanged.

The correct option, "c) count = count + 10;" takes the current value of count, adds 10 to it, and then assigns the result back to count, effectively increasing its value by 10.

User Zengod
by
7.9k points

No related questions found