I am a beginner in C programming language, recently I have studied about escape sequence.
\n means newline
\b means backspace
\r means carriage-return
When I am applying these on the following program, then I am getting output as hai, Can anyone please explain, how?
main()
{
printf("\nab");
printf("\bsi");
printf("\rha");
}
\r
is actually carriage return (which takes the cursor to the start of the line).
Your program outputs a new line (\n
) followed by "ab" then backspace (\b
) (over the b) "si", so you now have "asi" on the screen.
The \r
takes the cursor to the start of the line and then outputs "ha" leaving "hai" on the screen.
The first instruction will print ab
on a new line (\n
) :
>ab
The second instruction will make a backspace (\b
) before printing si
:
>asi
Then the last one will make a carriage return (\r
) before printing ha
:
>hai
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With