Pointer arithmetic on string literals with printf: determine the output. #include<stdio.h> int main() { printf(5 + 'CuriousTab '); return 0; }

Difficulty: Easy

Correct Answer: None of above

Explanation:


Introduction / Context:
This mirrors an earlier pattern: adding an integer to the pointer that results from a string literal moves the starting point for printing. Here, we must compute which substring begins at offset 5 of 'CuriousTab\n' and recognize which option matches the visible output.


Given Data / Assumptions:

  • String literal: 'CuriousTab\n' with indices C(0) u(1) r(2) i(3) o(4) u(5) s(6) T(7) a(8) b(9) \n(10).
  • Pointer passed to printf is &literal[5] → starts at 'u'.
  • The substring is 'usTab\n'.


Concept / Approach:
printf treats the passed pointer as a format string. Since 'usTab\n' contains no % directives, it prints as ordinary text. The visible output (ignoring the line break) is 'usTab'. None of the listed literal options exactly spell 'usTab', so the correct choice is the generic 'None of above'.


Step-by-Step Solution:

Compute offset 5 → character 'u'.Substring from that pointer → 'usTab\n'.Printed text → 'usTab' plus a newline.


Verification / Alternative check:
Changing the offset to 7 would print 'Tab\n'. To print the full word 'CuriousTab', use offset 0.


Why Other Options Are Wrong:

'CuriousTab' or 'CURIOUSTAB': do not match the substring starting at offset 5.'Error': the call is valid because the substring contains no format specifiers.'usTab': although this matches the actual text, it is not one of the provided explicit choices, hence 'None of above' is correct.


Common Pitfalls:
Off-by-one counting when indexing strings; assuming printf requires a % format when given a string literal as its only argument.


Final Answer:
None of above.

More Questions from Strings

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion