0
Is this code even correct?
I don't understand what this code means which is often used in the tutorials from sololearn, but nowhere else: int x = 1 int y = x++ //now in y stands 2 std:cout << ++y << endl what us this ++ thing in cout? it makes no sense and I don't think it's good programming behaviors especially for beginners.
3 odpowiedzi
+ 8
Line 'y=x++;' - y gets the value of x, so y is now 1, and then x++ increments the value of x, so now x=2
Line 'cout<<++y<<endl;' y gets incremented so y is now 2, and then it is printed
+ 4
go back and do lesson 1:11 Basic Concepts. Assignment and Increment EDIT: They explain it very well.
+ 1
ah yeah, so i got that correct. dont get me wrong,i work with C since 7 years, but i have never seen this kind of line with cout ... i was just wondering why they use it that way