Preface: Of course, writing constants to the left or right of the == operator has no effect on the operation itself, they are just two different writing styles. So I’m sure a lot of people aren’t going to change their style just because they read some post that says “constants should be on the left side.” After all, it’s just a habit.

! [](https://upload-images.jianshu.io/upload_images/24762785-c1368e9862313ec3.jpg?imageMogr2/auto-orient/strip%7CimageView 2/2/w/1240)

However, writing constants to the left of the operator may make it easier to check errors in some cases. Look at the following example:

Segment one, if and only if

flag == 5

Execute the contents of the loop body when:

int

flag;

.

For more information, please check out the image below, as well as free open source projects and courses.

! [](https://upload-images.jianshu.io/upload_images/24762785-bc23825696d4236b.gif? imageMogr2/auto-orient/strip)

while (flag == 5)

{

/* do something */

}

Segment two, the hand nearly knocked out a =, will cause an infinite loop, because

flag = 5

Always true. It is not easy to debug an error like this when the code volume is large:

int

flag;

.

! [](https://upload-images.jianshu.io/upload_images/24762785-f7ed28efb362a298.jpg?imageMogr2/auto-orient/strip%7CimageView 2/2/w/1240)

while (flag = 5)

{

/* do something */

}

In section 3, the constant is placed on the left, so it is safe to omit an = sign. The compiler will tell you that there is an Error:

int

flag;

.

! [](https://upload-images.jianshu.io/upload_images/24762785-2acb6e90c88578f9.jpg?imageMogr2/auto-orient/strip%7CimageView 2/2/w/1240)

while (5 = flag)

{

/* do something */

}

To sum it up in one sentence:

! [](https://upload-images.jianshu.io/upload_images/24762785-2bade4e6532327e1.jpg?imageMogr2/auto-orient/strip%7CimageView 2/2/w/1240)

Good writing style allows bugs to show up at compile time rather than run time.