C Test Incorrectly Uses printf() - Please Confirm



I took an online C test a few months ago. I actually thought the test
was better than some I've taken, but one question in particular I
think has the wrong answer. The question is this:

What is printed:

int a = 1;
printf("%d", ++a, a + 5);

a. 1
b. 2
c. 7
d. undefined

I selected d. This is the explanation given as to why b is the correct
answer.

The first expression in the parameter list following the format
string is paired with the first (and only) conversion specification.
The increment is a prefix so the result of the operation is the a + 1.
Since there are more items in the value list than there are conversion
specifications, the extra value is not shown.

I believe the correct answer is d because according to K&R2 (and by
implication the Standard) the order in which function arguments are
evaluated is not defined; in fact, K&R2's example, in Section 2.12,
shows the variable n being used twice in the same printf call (albeit
with the correct number of conversion specifications).

Am I correct that d is the correct answer?

--
Martin
.



Relevant Pages

  • Re: Why doesnt the standard allow reuse of arguments in printf() ?
    ... required by the conversion specifier. ... you can't mix numbered specifications with unnumbered ones in the same ... I concluded that none of these specs was a safe guide to actual practice. ... format string N times to obtain the Nth argument, or to stack up all N ...
    (comp.std.c)
  • Re: C Test Incorrectly Uses printf() - Please Confirm
    ... Since there are more items in the value list than there are conversion ... with the correct number of conversion specifications). ... It's the evaluation of the extra expression ...
    (comp.lang.c)
  • Re: C Test Incorrectly Uses printf() - Please Confirm
    ... Since there are more items in the value list than there are conversion ... The fact that the printf() will not use its third parameter does not ... with the correct number of conversion specifications). ...
    (comp.lang.c)
  • Re: MMV on Medieval Warfare (and stuff) - Rus Part Deux and a Half :-)
    ... system while the Russian bows had been made using the inch-based ... Conversion of the bowstrings required extensive ... paperwork and the Mongols simply refused to allow email exchange ... all specifications had to be converted from .pdf to .djvu ...
    (soc.history.medieval)