Tag

C

Browsing

There is one mistake that all C programmers make, regardless of experience.  You’ll do it often when you get started, but never completely stop.  The mistake?  Confusing the “assignment” operator with the “comparison” operator.  Take a look at this line of code:

[cpp] if (something = 0) {
[/cpp]

Notice the problem?  If not, then you might fall into this common trap.  The most annoying part?  A C-Compiler won’t give an error.  That code is legal C.  Legal code doesn’t mean you’ll get the results you expect.  In fact, this is probably not even close to what you wanted.   This simple mistake and why it “works” is explained below.