What is the difference assignment operators the equality operator?

I don't understand what and how different operators private from the equality operator
in one video C++ guy explained the construction of fi-else branching and wrote the program:
if (s=6 )
cout << "c=6 "
and then the same thing, but
if (s == 6 )
cout << "c=6"
explain what is the difference ?
August 23rd 19 at 10:46
3 answers
August 23rd 19 at 10:48
the difference is that
1) = assigns that to the left, one on the right. == Nothing assigns.
2) == compares what's on the left with the right. = Nothing compares, and only then returns the resulting value.

When you write if (x = y), then x is assigned the value y. Then this value gets to the if check. In C++ historically, no type true/false(boolean), it replaces the int. 0 is false, everything else true. Therefore, when y is not 0, executes the body if.

To write assignment in conditional constructions - a bad taste, because such code is harder to read. But you can write something in the spirit while(*dst++ = *src++);homework - try to understand what is written here, and what types should be in src and dst in order for it to be meaningful.

PS do not watch more videos of "that guy", he's kind of a strange way was chosen to explain if-else.
> In C++ historically, no type true/false
What is the truth? I think you two plus wrong (and 18 years) - Destin.Windl commented on August 23rd 19 at 10:51
: so I use Google)) - Carissa.OKee commented on August 23rd 19 at 10:54
: and it is quite possible :-D I'm here in the next issue mentioned what to say now "know C++" can not. Three years did not write, all is forgotten. But the conversion to bool works, right? - Ludwig_Miller commented on August 23rd 19 at 10:57
August 23rd 19 at 10:50
in the case
s = 6
variable recorded a value of s, this operation will return (if I remember correctly) the value that was assigned (6) that is not false and the if is triggered.
in the case
s == 6
the value of s is compared to the value 6 (and as previously, the variable s was rated 6, the condition is executed again)
August 23rd 19 at 10:52
I don't understand what and how different operators private from the equality operator

This is a completely different operation. Assignment operation writes a value into a variable. The comparison operation compares the values that you know are equal or not.

The assignment operation in if'e (the condition) not used never, but it can eventually appear because of a typo in the compare operation. And when you are prompted about it in any way will not be reported, because syntactically this notation is not considered wrong. So this typo can lead to subtle program error, as the program will just patioi't work correctly.

Find more questions by tags C++