This page may be out of date. Submit any pending changes before refreshing this page.
Hide this message.
Quora uses cookies to improve your experience. Read more
Robert Walker
It should be i=4.

i==4 is an expression for the computer to evaluate, not a declaration.

While
int i=4,j=12;

both declares i, and sets its value to 4.

You can have expressions in declarations, but it has to parse as an assignment to a variable.

Here is an example:

int i=4;
int j=
 i==4
 ?2
  :3;

(you need to know how the ? operator works to understand it though)

That sets j to 2 if i==4 and to 3 otherwise. In this examaple it sets j to 2 because from the previous declaration i==4.

So the issue isn't so much the ==,  but that what you have put there doesn't tell the compiler which variable you wish to declare or what value you want to assign to it.

The compiler would just parse it as (i==4) boolean expression,

As a boolean expression, it has value 0 if i is 4, and a non zero value if i is not 4. (That's how truth and falsity of boolean expressions is defined in C).

But i is not yet declared so there is no way to make this into a valid Boolean expression for the computer to evaluate.

Then the other problem is that it doesn't assign anything to anything. That's a bit like declaring int 0, j=12; - which doesn't assign the 0 to anything.

About the Author

Robert Walker

Robert Walker

Writer of articles on Mars and Space issues - Software Developer of Tune Smithy, Bounce Metronome etc.
Studied at Wolfson College, Oxford
Lives in Isle of Mull
4.8m answer views110.4k this month
Top Writer2017, 2016, and 2015
Published WriterHuffPost, Slate, and 4 more