What is the meaning of == and how does it differ from =?
How do I know which one to use?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
==is a test for equality.=is an assignment.Any good C book should cover this (fairly early on in the book I would imagine).
For example:
Just watch out for the heinous:
which is valid C and frequently catches people out. This actually assigns 4 to the variable
iand uses that as the truth value in theifstatement. This leads a lot of people to use the uglier but safer:which, if you accidentally use
=instead of==, is a compile-time error rather than something that will bite you on the backside while your program is running 🙂The logical-or operator is two vertical bar characters, one after the other, not a single character. Here it is lined up with a logical-and, and a variable called
b4:No magic there.