# Difference between = and ==

I started learning the programming language C++ yesterday. Today while learning if/else, I typed = instead of == and couldn’t identify the error until my elder sis (who’s the one teaching me to code) stepped in and told me. She also was the one to make me write this, so that I really understand it and not repeat the same mistake.

So my fellow readers, if there are any, this is what I understood-

In my words, = is used when we assign the value.

For example- if I write int a = 5, I’m telling the computer that the value of a is 5 and that wherever I use the variable ‘a’, the value that should be taken is 5. I’m telling the computer that the left side’s value is the right side.

or int e=r means that the value of e is to be taken r.

But == is used when I’m comparing two things or if checking for a condition.

For example- if (a==60 and b==60 and c==60) { cout<<“equilateral triangle”;} , here I’m comparing a with 60, I’m telling the computer to check if the left side is equal to the right side.

or (a==b), here I’m comparing a and b like I’d do with <,>

comparing both,

1. a=b → the value of a is b

a==b → the value of a is equal to the value of b.

(as value of, 5 =|-5| or 2+3+4=1+3+5, LHS and RHS are different but their values are same. Equal to sign is used as mathematical operation and not c++ operation for understanding of the concept.)

2. sum = a+b+c , here the variable sum has the value a+b+c

sum==a+b+c , here we compare if a+b+c is equal to the value of the variable sum.