0

What is the differences between = and == in c++ programming

6th Dec 2017, 7:44 AM
Yasin Sharifi
Yasin Sharifi - avatar
4 Answers
+ 15
= is used when you want to assign a value to a variable eg: int x= 7; //will assign a value of 7 to x == is used to check a condition eg: if(x==7){ //some code } This will check whether x is equal to 7 If it is, the loop gets executed If not, it gets ignored
6th Dec 2017, 7:47 AM
Frost
Frost - avatar
+ 2
'=' is assignment operator, viz a = b; // Read as 'Value of b is assigned to a' '==' is comparison operator, viz a == b; // Returns true if 'a is equal to b'
6th Dec 2017, 8:09 AM
#RahulVerma
#RahulVerma - avatar
+ 2
the main difference between = and == is that in c = refers to the assignment operator .for example let's take a simple snippet code . int a; b=10; it initializes variable a of integer type. then assigns the value 10 in b . But the ==operator is pretty much different .here it refers to the decision making statements. for example if(i%2==0) printf("I is even"); else printf ("I is odd"); therefore it check the condition otherwise it is used as a comparison term. hope you guys understood if any queries ask me.
6th Dec 2017, 9:05 AM
joffie
joffie - avatar
+ 2
In C = assigns the value to a variable and == checks whether the condition satisfies (generally used in decision making concept)
8th Dec 2017, 8:28 AM
Alisha Ahmed
Alisha Ahmed - avatar