Use of " ? : " in format param to printf

Robert Seals rds95 at leah.Albany.Edu
Fri Jan 20 03:17:19 AEST 1989


I have a question.

main()
{
    double sum;
    int count;

    /* ..... */

    printf(count == 0 ? " ---- " : " %4.0lf ", sum / count);
}

(If something is dopey, just ignore it because the main thing is...)

Does it matter if there are unused arguments to printf? That is, if
'count' is zero, will anything be screwed up because there is extra
crud in the code? The actual application I'm doing is much more
complicated than this (REALLY??), but the principal is the same.
Is this OK code? Lint didn't mind, nor did gcc -Wall.

rob



More information about the Comp.lang.c mailing list