+ 1

What is speicial with int c=9?

Why c=9 behave diferently fro example c=2 in cout? https://code.sololearn.com/c3CBrMQA6X9L/?ref=app

25th Dec 2019, 1:34 PM
Nadav Vinik
Nadav Vinik - avatar
5 odpowiedzi
+ 3
it does exactly the same. an increase of two. it doesn’t print 911 also not 9 1 1 no it prints 9 11 which is an increase of 2 same as 2 4 (also increase of 2) if you don’t know why: c++ prints the number first and then increases it by 1 so c = 9; cout << c++ (prints c first which is 9 and then increases it, so after printing it it becomes 10 if you follow that by ++c the following happens ++c increases first and then outputs so c = 9 cout c++ (prints 9 increases to 10) (c is now 10) cout ++c (increases to 11 first and then prints)
25th Dec 2019, 1:38 PM
Brave Tea
Brave Tea - avatar
+ 4
Nadav Vinik , I think you are a bit confused It is same for both value 9 and 2 I have just added comments to your code to explain what is happening. Just have a look at it👇 https://code.sololearn.com/c8khAwo5QDiz/?ref=app
25th Dec 2019, 1:41 PM
Arsenic
Arsenic - avatar
+ 2
That's because of Post and Pre increment operator. Check them out from the link below to see how they works https://www.sololearn.com/learn/CPlusPlus/1610/
25th Dec 2019, 1:38 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 2
Look there are two types for increment 1- postfix = c++ 2- prefix. = ++c And the compiler compile from left to right then it will increase one to the variable when it find ++ For example ++c it will increase c by one and then cout it because ++ is first
25th Dec 2019, 2:12 PM
ycsvenom
ycsvenom - avatar
+ 1
Thanks. I should see it :(
25th Dec 2019, 1:42 PM
Nadav Vinik
Nadav Vinik - avatar