Select the correct output of the following C++ program segment, assuming all…

2022

Select the correct output of the following C++ program segment, assuming all necessary header files are correctly included.

  1. A.

    itence

  2. B.

    tance

  3. C.

    Tence

  4. D.

    Inheri

Attempted by 231 students.

Show answer & explanation

Correct answer: B

Final output: tance

  1. Write the string with indices to locate characters: I n h e r i t a n c e

    Indices: 0 1 2 3 4 5 6 7 8 9 10

  2. S initially points to index 0 (character 'I').

  3. S += 6 advances the pointer to index 6, which is the character 't'.

  4. cout << S prints the string starting at that pointer until the null terminator, producing "tance".

Note: In modern C++ string literals have type const char[]. Assigning them to a non-const char* is deprecated or ill-formed in some compilers, but assuming the code compiles, the printed output is "tance".

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Uppsc Polytechnic Lecturer 2025 Cs