c - An Abstrusing printf() expression -
while reading random code, happen encounter printf()
expression bit strange me, statement this
void printdiceface(int n){ printf("%d 0 %d\n%d %d %3$d\n%2$d 0 %1$d\n\n",n>50,51%n%2,n>53,n%2); }
this obfuscated version of snippet prints face of electronic dice. example.
please explain printf()
statement in detail.
the format results in:
<num1> 0 <num2> <num3> <num4> <num3> <num2> 0 <num1>
with numbers being either 0 or 1 depending on result of operations later on. unusual thing in format string use of %<n>$
- says parameter, arg<n>
of function (instead of 'the next' in order) should used. example, if specify:
printf("%d %1$x\n", 10);
it prints '10 a'.
Comments
Post a Comment