+ 2
Int a= 10; a=a++*a--; it is coming 110 why??? C programming
C programming
17 Antworten
+ 4
a++ and a— are post-increment operators, so it becomes a=(10)*(10+1).
The a–– is applied after multiplying, but before a is assigned again, so it is has no effect.
+ 7
Khushi Joy
Because after a++ a will be 11 so 10 * 11 = 110
Remember here a-- is post increment so it will first assign value
+ 4
Mr.Imperfect
You can't change logic to prove yourself.
+ 3
Mr.Imperfect
Why you are focusing on warning? Why you don't see her problem. Whatever error comes doens't matter. If she asked why 110 then definitely she checked her logic then asked here.
+ 3
Please tag C-language rather than 'ishjaiwal' to improve language context clarity 👍
You can mention your friend in the thread's Description by typing @ followed by a name you can pick from a pop-up menu. Mentions do not work in question title or tags 👌
+ 2
Mr.Imperfect
See the problem again there is a-- not b--
+ 2
Your question:- a=a++*a-- = 110
Because you have put the value of 'a' as 10.
If we consider (a++)only this much it's value is 10 because you used the increment operator as post fix.
And then if we consider(a--)this would be 11 as 1 + 10 = 11 and the decrement operator you used post fix NOT prefix.
And 10 × 11 = 110
+ 1
Thank you I got it
+ 1
Mr.Imperfect
Did I say prefix?
+ 1
Mr.Imperfect
After assigning the value of a will be 11
so a++ * a--
= 10 * 11 = 110
See here output is 110 and ignore the warning because it is just a warning not error.
https://code.sololearn.com/c04TD0FX7Qrf/?ref=app
For more clarification see another example
https://code.sololearn.com/c8z0CM6t354B/?ref=app
+ 1
Mr.Imperfect
Why should be -1?
I think you are still not clear about post increment and pre increment. See more example on google.
0
Because
you used post fix in operation it goes like
a=10*11;//i.e 10+1 after incriminate
0
It is confusing, but a++ and a-- cancel each other.
- 1
U should see more operations on C
- 1
Here initially value of a is 10
Now value of a++ is 11
So a++*a-- = 10*a--
Now the value of a-- is 10 (because value of a is 11 due to a++)
So a++*a-- = 11*10 = 110