+ 2
what is difference between " = "and" == " in Programming?
7 Réponses
+ 7
= assignment operator
a=5;
assigns value of 5 to a
== equality operator
if a=5,b=6;
a==b;
Checks whether they both are equal here output is false
+ 4
= is used for assignment
And == is used for comparison
Simple is that
+ 2
= this is called assignment operator use to assign value
Example
Int a=2;
Var b=20;
== This is called comparison operater use to compare to value mostly in if , else conditions .
Example
If ( a==b)
{
Console.WriteLine("ok");
}
If ( a==b)
{
Document.Write("ok");
}
+ 1
and there is also ===
You can use this to compare two variables or values AND it checks if the type (string, number, boolean) is the same.
+ 1
There are three kinda operators usage
1)
x=5, y=3+2 are assignment of value
2)
x==y is equation of values, that compares values of variables
3)
x===y is kind of a strict equation which compares value and type of variable. (e.g. x=3+2, y='3+2' doesnt gets the same result)
Almost the same concept applies to +, ++ OR mixed +=, -= according to the operators nature.
0
in my words "=" is use for assign the value to variables and its also called assignment opreator on the other hand "==" is use for compare the value of variable.
0
= is assignment operator:
example: if you will reffer to a value more than once in your program, you may want to assign that value to a variable like this:
myValue = "SoloLearn".
and == is a comparison operator .... so when you want to make so comparisons on values or types of values you will use it
example:
valid_age = 18
my_Age = 18
valid = my_age == valid_age
in this example I compared numbers. :)