What is the difference between the = symbol and == symbol?

What is the difference between the = symbol and == symbol?

Senior Developer Asked on February 11, 2017 in C.
Add Comment
1 Answer(s)

One of the most common mistake that a programmer can make is to confuse the equal sign (=) with a double equal signs (==).
When we wish to assign a value to a variable or member, we use the equals sign (=).
For example:


x = 1 + 4; // assignment operation

When we wish to make a comparison, such as in an if statement, we use the double equals sign (==).
For example:


if ( x == y ) { System.out.println ("Match found!"); }  // comparison

Senior Developer Answered on February 22, 2017.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.