+ 2

Int a= 10; a=a++*a--; it is coming 110 why??? C programming

C programming

7th Feb 2021, 10:26 AM
Joy
Joy - avatar
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.
8th Feb 2021, 4:53 AM
Cryend
Cryend - avatar
+ 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
7th Feb 2021, 10:28 AM
A͢J
A͢J - avatar
+ 4
Mr.Imperfect You can't change logic to prove yourself.
7th Feb 2021, 12:03 PM
A͢J
A͢J - avatar
+ 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.
7th Feb 2021, 12:06 PM
A͢J
A͢J - avatar
+ 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 👌
7th Feb 2021, 12:18 PM
Ipang
+ 2
Mr.Imperfect See the problem again there is a-- not b--
7th Feb 2021, 12:01 PM
A͢J
A͢J - avatar
+ 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
9th Feb 2021, 3:51 AM
Shailendra Kumar
Shailendra Kumar - avatar
+ 1
Thank you I got it
7th Feb 2021, 10:35 AM
Joy
Joy - avatar
+ 1
Mr.Imperfect Did I say prefix?
7th Feb 2021, 11:21 AM
A͢J
A͢J - avatar
+ 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
7th Feb 2021, 11:24 AM
A͢J
A͢J - avatar
+ 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.
9th Feb 2021, 4:38 AM
A͢J
A͢J - avatar
0
Because you used post fix in operation it goes like a=10*11;//i.e 10+1 after incriminate
9th Feb 2021, 4:22 AM
Ritik kuhite
Ritik kuhite - avatar
0
It is confusing, but a++ and a-- cancel each other.
9th Feb 2021, 10:14 AM
Xarbi Goals
Xarbi Goals - avatar
- 1
U should see more operations on C
8th Feb 2021, 10:39 AM
Lamya Alahyane
Lamya Alahyane - avatar
- 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
8th Feb 2021, 3:55 PM
Sumant kumar
Sumant kumar - avatar