Predict the output of the given below code int main() {…

2026

Predict the output of the given below code

int main()

{

printf("\new_c_question\by");

printf("\rTCS");

getchar();

return 0;

}

  1. A.

    new_c_questioy

  2. B.

    ew_c_questioy

  3. C.

    TCSc_questioy

  4. D.

    ew_c_questioy TCS

Attempted by 114 students.

Show answer & explanation

Correct answer: C

Concept

In C, several escape sequences are cursor-control codes rather than printable characters. \n starts a new line; \b (backspace) moves the cursor one column to the left without deleting, so the next character overwrites whatever was there; and \r (carriage return) moves the cursor to column 0 of the current line, again without erasing. The visible text on a line is whatever occupies each column after all overwrites have happened.

Applying it to this code

  1. printf("\new_c_question\by"); The leading \n opens a new line, then the remaining characters are written, so the line reads ew_c_question (the backslash-n consumes the letter n).

  2. \b steps the cursor back onto the final letter, and the y that follows overwrites it, so the line now reads ew_c_questioy.

  3. printf("\rTCS"); The \r returns the cursor to column 0 and TCS overwrites the first three columns, so the line becomes TCSc_questioy.

  4. getchar(); waits for a keypress and prints nothing.

Cross-check

Column by column: columns 0-2 now hold T, C, S from the second printf; columns 3-11 keep c_questio unchanged; column 12 holds y from the backspace overwrite. Reading straight across gives TCSc_questioy.

Explore the full course: Coding For Placement