printf

Wm E Davidsen Jr davidsen at crdos1.crd.ge.COM
Tue Oct 24 00:21:21 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 ?

  I have no idea what it means, I can explain what it does... "%d"+a is
a form of address plus integer expression notation. It evaluates to the
*address* of the a'th character in the format. It also could be written
as &("%d"[a]) if you wish. I have no idea why anyone would do this, and
if a ever has a value other than zero or one when this executes it will
be non-portable. For a==0 the value of b will be printed, while for a==1
the character d will be printed.

  This is either a typo or some really obscure C.
-- 
bill davidsen	(davidsen at crdos1.crd.GE.COM -or- uunet!crdgw1!crdos1!davidsen)
"The world is filled with fools. They blindly follow their so-called
'reason' in the face of the church and common sense. Any fool can see
that the world is flat!" - anon



More information about the Comp.lang.c mailing list