Everything2
Near Matches
Ignore Exact
Full Text
Everything2

==

created by chromatic

(thing) by Noung (54 min) (print)   ?   (I like it!) 1 C! Sun Nov 18 2001 at 1:29:41

Used in many programming languages (mostly those derived from C) to denote an equality operator. It is a binary operator that will return 1 if the left-hand operand is lexicographically equivalent to the right-hand operand and 0 otherwise.

Example in C-

int a;
a = 5;
if ( a == 5 ) printf("Hi mom.\n");

Will print "Hi mom.\n" because a is 5.

However, there can be problems. Newbie programmers (and some not-so-newbie programmers) tend to get == (the equality operator) mixed up with = (the assignment operator).

int a;
a = 5;
if ( a = 5 ) printf("Hi mom.\n");

That code assigns a value of 5 to a, then evaluates a to see if it has a value - which it always will do! Some compilers will flag this with a warning message such as "Expression always true.", but some won't. This can be quite a hard problem for a newbie to solve. (If you were to put a = 0, the inverse would happen: the compiler would complain that the expression was always false).

One way to solve this problem is to write your expression like this -

if ( 5 == a )

If you accidently write = instead of == there, your compiler will make an error at compile-time because you are trying to assign a value to an actual number, which is illegal. This will mean you don't have a nasty run-time error to deal with.

However, the above way is a bit ugly, and the best way to deal with this problem is just to learn not to make the mistake. Once you've done it a few times you're unlikely to do it again.


printable version
chaos

:= != ?: Power Supply = Cookies
= dec 25 = oct 31 Star Wars as an allegory of coming to terms with homosexuality White Light White Heat White Trash
Reasons you should take up guitar E2 clueless (newbie) mistakes to avoid A&W Mug Proposal for a new system to help introduce new users into E2
Stephen Hawking equality politically correct junior high
Alan Turing PHP Assignment lvalue
rvalue Nirvana everyone :)
Y'know, if you log in, you can write something here, or contact authors directly on the site. Create a New User if you don't already have an account.
  Epicenter
Login
Password

password reminder
register

Everything2 Help

Cool Staff Picks
Things you could have written:
Jack Kerouac character reference key
They hit each other, like fucking Christ intended!
Sumerian
Bible Code
Why Angled Shots are Easier than Straight Shots
The seriously red dress
Beveridge Report
Jim Crow
Omegranite pomegranite pomegranite pomegranite pomegranite pomegranite pie
Bunyip
Poetry you found that you wrote when you were ten but secretly still like
September 11, 2002
Moai
New Writeups
antigravpussy
One fly amongst many(person)
sam512
Moon Base Shackleton, 1978(fiction)
Pavlovna
toy boy(person)
XWiz
tear jerker(review)
Heitah
Anarchy is Order(idea)
jessicaj
July 26, 2008(dream)
Berek
ABBA(person)
devolution
k-hole(place)
Nadine_2
The Sound Of Madness(review)
SwimmingMonkey
Conversations with Fo Fo, the Loneliest dog in Purgatory(fiction)
locke baron
lynx(thing)
Simulacron3
Reality, Dimensions and the Natural Ontology(essay)
SubSane
Making Love to a 9-Foot Woman(person)
Ouzo
Thoughts(idea)
antigravpussy
I fall silent, listening. The breadcrumbs are talking about us(person)
This affordable entertainment brought to you by The Everything Development Company