#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# Increment and decrement operator

Member Posts: 2

Int main()
{
a=10;
a=a++;
a=a++ * a--;
print("%d",a);
}
I don't get why the output is 110 plz explain the output

• Member Posts: 115 ✭✭✭

First off, your code is not even valid C.

``````a = 10
a = 10
a = 11 * 10
``````

• Member Posts: 2

Hey boo ,sorry I didn't mention that a is int data type, but u didn't explain it well why in last line it's 11*10

• Member Posts: 115 ✭✭✭

What do you expect it to be? On line 2 assignment precedes the increment. On line 3 it's an expression so increment/decrement need to be evaluated first before both numbers are multiplied.
Maybe this will be more clear:

``````a = 10
(a = a + 1) * (a = a - 1) // a++ * a--
``````
• Member Posts: 14

Assignment operator preceds the increment. Moreover, the value of a is initialised to be 10 and then multiplied with 11 which gives the result 110. For help on operators in C, follow the link : http://knowledgetpoint.com/csharp/csharp-language-fundamentals/