217k views
5 votes
What is the output of the following program segment?

int x = 0;

++x;

x++;

++x;

x++;

++x;

1 Answer

4 votes

Answer:

5

Step-by-step explanation:

The operator 'x++' is called the post increment operator, it is assign first and then increment.

The operator '++x' is called the pre increment operator, it is increment first and then increment.

So, both are increment operator which increment the value by one.

initially the value of x is zero,

++x increase the value to 1 and than assign to x.

then, x++ it assign to x first then increment by 1 means x=2

and so on.....

Their are five increment operator are used. so, the result is 5.

User Cfpete
by
5.1k points