Output of Following program is : hai
I didn't get how the \r
carriage return works in this program and in real can any one help me out ?
#include <stdio.h>
#include<conio.h>
void main()
{
printf("\nab");
printf("\bsi");
printf("\rha");
_getch();
}
This question is related to
c
Step-by-step:
[newline]ab
ab
[backspace]si
asi
[carriage-return]ha
hai
Carriage return, does not cause a newline. Under some circumstances a single CR or LF may be translated to a CR-LF pair. This is console and/or stream dependent.
Program prints ab
, goes back one character and prints si
overwriting the b
resulting asi
.
Carriage return returns the caret to the first column of the current line. That means the ha
will be printed over as
and the result is hai
Source: Stackoverflow.com