Quantcast
Channel: Tips for golfing in C - Code Golf Stack Exchange
Viewing all articles
Browse latest Browse all 67

Answer by badatgolf for Tips for golfing in C

$
0
0

Use bitwise operators for boolean conditions

For example:

if(a||b) /* do something */

This saves one byte:

if(a|b) /* do something */

Respectively, a!=b becomes a^b and a&&b becomes a&b

An example of using this trick.

Note that sometimes you have to use ||. For example:

if(!a)b++

can be written as

a||b++

but

a|b++

doesn't work.


Viewing all articles
Browse latest Browse all 67

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>