What is the difference between "=" and "==" operator?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

What is the difference between "=" and "==" operator??

In c++ only Can anyone explaine. And when to use each one

20th Jan 2021, 6:05 AM
ĴØ€ĴØ
ĴØ€ĴØ - avatar
7 Answers
+ 4
= is an assignment operator == compares values
20th Jan 2021, 8:01 AM
D_Stark
D_Stark - avatar
+ 8
= is used for assignment between variables and value. Example: int x = 5; == is used for comparison and conditions Example: if (x + y == 5) And please Kindly use the search bar first before asking. Thanks! https://www.sololearn.com/Discuss/1652195/and-in-c https://www.sololearn.com/Discuss/1084542/vs https://www.sololearn.com/Discuss/918660/if-statements-vs https://www.sololearn.com/Discuss/1171728/difference-between-and https://www.sololearn.com/Discuss/842952/the-difference-between-and
20th Jan 2021, 6:12 AM
noteve
noteve - avatar
+ 3
TheGirlHasNoName this was a C++ question. There is no === in C++.
21st Jan 2021, 7:22 PM
Sonic
Sonic - avatar
+ 3
TheGirlHasNoName that's OK. No problem.
21st Jan 2021, 9:46 PM
Sonic
Sonic - avatar
+ 2
= is for assigning value to a variable == is used to test equality between two expressions we can use it in loops in conditions for test . === it is used to test equality between two expression + to compare the types of both expressions Example: Boolean a = '1'===1; The value of a is false because'1' is type string and 1 is type int
21st Jan 2021, 6:48 PM
Nassera
Nassera - avatar
+ 1
Thank you Sonic i thought it was the same for java and c++
21st Jan 2021, 7:36 PM
Nassera
Nassera - avatar
+ 1
= operator declares a value for ex a=10 While == operator is a relational operator as the name suggests it compares two value
22nd Jan 2021, 2:32 AM
Aditya Mishra