printf

Fred Smith fredex at cg-atla.UUCP
Sun Oct 22 11:18:13 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 ?



"%d" evaluates to a POINTER to a char, i.e., char *. It is legal to
add an integer to a pointer, so if one assumes that (a) represents an
integer value, this would pass the value of the pointer, offset by the
value of the integer expression a, as the first parameter of the
printf call. God alone knows WHY anyone would want to do that, but,
yes, it does appear to be legal C.

Fred



More information about the Comp.lang.c mailing list