0
What is the differences between = and == in c++ programming
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
+ 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'
+ 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.
+ 2
In C
= assigns the value to a variable
and
== checks whether the condition satisfies (generally used in decision making concept)