C Interview Questions and Answers

 

I came across some code that puts a (void) cast before each call to printf. Why?

printf does return a value (the number of characters printed, or an error code),
though few programs bother to check the return values from each call. Since some
compilers (and lint) will warn about discarded return values, an explicit cast to
(void) is a way of saying ``Yes, I've decided to ignore the return value from
this call, but please continue to warn me about other (perhaps inadvertently) ignored
return values.'' It's also common to use void casts on calls to strcpy
and strcat, since the return value is never surprising.

Posted by:Richards