Basic and Advance C Question:

Download Job Interview Questions and Answers PDF

I had a frustrating problem which turned out to be caused by the line

C Programming Interview Question
C Programming Interview Question

Answer:

I had a frustrating problem which turned out to be caused by the line
printf("%d", n);
where n was actually a long int. I thought that ANSI function prototypes were supposed to guard against argument type mismatches like this.

When a function accepts a variable number of arguments, its prototype does not (and cannot) provide any information about the number and types of those variable arguments. Therefore, the usual protections do not apply in the variable-length part of variable-length argument lists: the compiler cannot perform implicit conversions or (in general) warn about mismatches. The programmer must make sure that arguments match, or must manually insert explicit casts.
In the case of printf-like functions, some compilers (including gcc) and some versions of lint are able to check the actual arguments against the format string, as long as the format string is an immediate string literal.

Download C Programming Interview Questions And Answers PDF

Previous QuestionNext Question
How can I write a function that takes a format string and a variable number of argumentsHow can f be used for both float and double arguments in printf? Are not they different types?