Can anyone please tell me how the value of counter remains the same as 1? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Can anyone please tell me how the value of counter remains the same as 1?

https://code.sololearn.com/ccCR7RJ1HiOV/?ref=app

31st Jul 2022, 8:46 AM
Keerthana.S
Keerthana.S - avatar
4 Answers
+ 2
Hoping you have your correct code about your task... You're welcome..
31st Jul 2022, 10:10 AM
Jayakrishna 🇮🇳
+ 2
count = count++; It's post increment, It will be evaluated as first current count values used in instruction, then count incremented by one and stored in count. Next instruction result is back stored in lvalue that is again count. Here it replacing instruction result with post increment. So due to override, it's lost in increment so value remains same.. If you use any other variable as lvalue, you can retain count increment value.. counter = count++; so bath have different values... Hope it helps...
31st Jul 2022, 8:59 AM
Jayakrishna 🇮🇳
+ 2
Thank you so much Jayakrishna🙏🏻 again you're the one who helped me clarify my doubts
31st Jul 2022, 10:08 AM
Keerthana.S
Keerthana.S - avatar
+ 2
U have written count =count++... But it should either be count = count+1.... Or only count++
1st Aug 2022, 8:50 AM
Shruti Bubna
Shruti Bubna - avatar