88.5k views
5 votes
What is the value of x after the following

int x = 5;

x++;

x++;

x+=x++;

A)14
B)10
C)13
D)15

1 Answer

3 votes

Answer:

Option D: 15 is the right answer

Step-by-step explanation:

Initially, the value of x is 5

Note- x++ is a post-increment operator which means the value is first used in the expression and then increment.

After executing the x++, the value of x is 6

similarly again executing the next line and right now the value of x is 7

At last the value of x is 15.

User Vishal Seshagiri
by
7.7k points

No related questions found