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

Answer by dingledooper for Tips for golfing in C

$
0
0

dprintf for conditional printing

As you may know, printing something by a condition can be done with ?:, && or ||:

cond&&printf("%d\n",n);cond||printf("%d\n",n);cond?:printf("%d\n",n);

Another interesting idea is to use dprintf, which is the same as printf except that it takes an extra argument, specifying the output file descriptor. It will only output to STDOUT if said argument is equal to 1. This can be abused to potentially save a few bytes over the previously mentioned methods:

x-1||printf("%d\n",n);dprintf(x,"%d\n",n);

Viewing all articles
Browse latest Browse all 67

Trending Articles



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