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


This Question Belongs to C Program >> C Miscellaneous

Join The Discussion

Comments ( 10 )

  1. Deepak Goyal
    Deepak Goyal :
    4 years ago

    n - newline - printf("nab"); - Prints ab
    b - backspace - firstly 'b' removes 'b' from 'ab ' and then prints 'asi'.
    r - currsor point to start and then ha overrides as and then print hai

  2. Dev Sharma
    Dev Sharma :
    4 years ago

    I am getting your point clearly

  3. Shubham Soni
    Shubham Soni :
    6 years ago

    why
    skip only first 2 spaces

  4. Pulkit Sachdeva
    Pulkit Sachdeva :
    6 years ago

    i am getting absiha at repl.it and codefroblocks.

  5. Pavan Kalyan
    Pavan Kalyan :
    7 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

  6. Pavan Kalyan
    Pavan Kalyan :
    7 years ago

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

  7. Kakkar Mohit
    Kakkar Mohit :
    7 years ago

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

  8. Barbarous Pranav
    Barbarous Pranav :
    7 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)


  9. Ameen Althaf
    Ameen Althaf :
    7 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'

  10. Mala Gowda
    Mala Gowda :
    7 years ago

    As per the example answer is "asiha" right?

Related Questions on C Miscellaneous