printf

Doug Gwyn gwyn at smoke.BRL.MIL
Sun Oct 22 08:36:43 AEST 1989


In article <543 at uwm.edu> zhao at csd4.csd.uwm.edu (T.C. Zhao) writes:
>I recently came across a piece of c code:(both a and b are integers)
>printf("%d"+(a),b);
>in passes compiler without any problem, what does this code mean ?

It means what it says, namely the format string passed to printf()
depends on the value of the variable a; a must be 0, 1, or 2
(corresponding to equivalent format strings "%d", "d", and ""), and
in the latter two cases printf() will ignore the second argument (b).

I can see using such a trick in some other cases, but this doesn't
seem to be a wise use of it.



More information about the Comp.lang.c mailing list