What will be the output of the code given below?
Qualcomm technical mcq question, verified with a worked answer. Free to practise - no sign-up.
What will be the output of the code given below?
printf("ab", "cd", "ef");a
**MCQ
Show answer & explanation
Answer: D. ab
The printf() function interprets its first argument as a format string. Since "ab" contains no format specifiers (like %s, %d, etc.), it is printed literally. The additional arguments "cd" and "ef" are passed but ignored because there are no corresponding format specifiers to consume them. Therefore, only "ab" is printed.
Step-by-step Derivation:
Step-by-step execution:
- printf() is called with three string arguments: "ab", "cd", "ef"
- The first argument "ab" is the format string
- The format string "ab" contains no format specifiers (no % characters)
- Since there are no format specifiers, printf() simply outputs the format string as-is: "ab"
- The extra arguments "cd" and "ef" are ignored—they are never accessed or used
- Output: ab