Difference between equal to (==) and assignment operator(=)? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Difference between equal to (==) and assignment operator(=)?

20th May 2023, 9:16 AM
𝘾𝙤𝙙𝙚 𝙒𝙞𝙩𝙝 𝘿𝙖𝙧𝙠
5 Answers
+ 9
Assignment operator: used for asigning a value to a variable. int num = 4; ^ Equal to operator: used for comparing two variables: cout << 1==0; // prints 0 (false) cout << 1 == 1; // prints 1 (true)
20th May 2023, 9:28 AM
Ugulberto Sánchez
Ugulberto Sánchez - avatar
20th May 2023, 9:57 AM
Sakshi
Sakshi - avatar
+ 2
𝘾𝙤𝙙𝙚 𝙒𝙞𝙩𝙝 𝘿𝙖𝙧𝙠 '=' sign used for assigning variables :- Eg. int x=0; And '==' sign is used for comparisons :- Eg. if(x==0){cout<<"Hello";}
21st May 2023, 4:07 PM
Alhaaz
Alhaaz - avatar
+ 2
The equal operator, means that whatever is coming after that, is getting assigned to that variable. The equal to operator, compares one value with the other. Here is an example: int number = 1; Here is an example of the comparison operator: if(number1 == number2){ cout <<"Hello"
22nd May 2023, 2:42 PM
Danish Zubair
Danish Zubair - avatar
+ 1
"==" this used for comparison and "="this is used for assigning value to variables and constants
21st May 2023, 2:55 PM
G Ramya