Archived

This topic is now archived and is closed to further replies.

question on ==

This topic is 6121 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

ok i want to know exactly what this is....yes im a newbie as its easy to tell heres an example else if(age==100) whats the "==" in the above thing for is there a particluar reason why there is two equal signs to say that its equal? - Grimey

Share this post


Link to post
Share on other sites
It tests for equality.
When you use one = sign, it is an assignment statement.
val = 5; // the number 5 is put in val
(val == 10); // see if val contains the value 10

Martee
Magnum Games.NET
All your code are belong to us.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
okay look at the following code:

---
int age = 0;
if (age == 0)
do something here

if (age = 10)
do something else
---

the difference is that the "==" is a test for equality, whilst the "=" is a assign operator. So age == 0 returns true or false. Whilst age = 0 says let age be 0.

Share this post


Link to post
Share on other sites
The "==" operator is an equality operator. This is NOT the same as the "=" operator which is the assignment operator.


As an example:

age = 100;
This assigns the value of 100 to the variable age.

(age == 100)
This compares the value that is in age to 100. If it is the same then the expression is evaluated to true.


So you could say:
bool isEquals = ( age == 100 )

This assigns isEquals to either true if age is equal to 100 or false if not.





-------
Andrew

Share this post


Link to post
Share on other sites