Examveda
Examveda

Determine the Final Output:
void main()
{
      printf("\nab");
      printf("\bsi");
      printf("\rha");
}

A. absiha

B. asiha

C. haasi

D. hai

Answer: Option D

Solution(By Examveda Team)

\n - newline - printf("\nab"); - Prints ab
\b - backspace - printf("\bsi"); - firstly '\b' removes 'b' from 'ab ' and then prints 'si'. So after execution of printf

Join The Discussion

Comments ( 9 )

  1. Dev Sharma
    Dev Sharma :
    4 months ago

    I am getting your point clearly

  2. Shubham Soni
    Shubham Soni :
    2 years ago

    why
    skip only first 2 spaces

  3. Pulkit Sachdeva
    Pulkit Sachdeva :
    2 years ago

    i am getting absiha at repl.it and codefroblocks.

  4. Pavan Kalyan
    Pavan Kalyan :
    3 years ago

    I am not able to get answer that you specified , I am getting absiha, I tried in different compilers but getting the same answer

  5. Pavan Kalyan
    Pavan Kalyan :
    3 years ago

    I am not able to get answer that you specified , I am getting absiha

  6. Kakkar Mohit
    Kakkar Mohit :
    3 years ago

    Now, a carriage return means to go back to the beginning of the line. So the "ha" overwrites the "as" in "asi:

  7. Barbarous Pranav
    Barbarous Pranav :
    3 years ago

    Exact Solution...

    ab
    b : back one character
    write si : overrides the b with s (producing asi on the second line)
    r : back at the beginning of the current line
    write ha : overrides the first two characters (producing hai on the second line)


  8. Ameen Althaf
    Ameen Althaf :
    3 years ago

    no, if u don't put /r then it should be print as "asiha",
    in our program in last statement we have /r so it removes first two character an prints ha in place of it therefore output is 'hai'

  9. Mala Gowda
    Mala Gowda :
    3 years ago

    As per the example answer is "asiha" right?

Related Questions on C Miscellaneous