0

How it works plz explain me

printf("\nab"); printf("\bsi"); printf("\rha"); ans is hai how ?? plz explain step by step

15th Nov 2017, 4:32 PM
corejava
2 Answers
+ 1
First print ab in new line \n ab then Second printf \b backspace so output becomes asi then third one is carriage return \r so output is hai
15th Nov 2017, 4:42 PM
Nanda Balakrishnan
+ 1
first line prints on a new line : ab \b in 2nd line takes the cursor back by one character, thereby deleting 'b' in ab and then printing 'si' making the screen/console display: asi \r in 3rd line places the cursor at the beginning of current line and starts printing from there, while overwriting the existing 'as' part of the text 'asi' with 'ha' thereby making the console display : hai word of caution though! except for \n (newline) almost all other escape sequences are bound to vary depending upon the underlying implementation/OS in question. Therefore, the above output is merely theoretical and may not be the product across all systems.
15th Nov 2017, 4:52 PM
Anil
Anil - avatar