views:

41

answers:

1
#include <stdio.h>
main()
{

   printf("az\b\b");

   printf("s\ni");

}

above program when compiled with gcc gives output

sz

i

Can someone help us out to understand the output

+3  A: 

That's because your console interprets '\b' as a backspace character.

sbi
But why is z printed after s.
santhosh
Can you please explain the answer using your reasoning.
santhosh
@santosh: Your program prints `az`, then moves the cursor backwards twice (now it's back at the beginning of the line), writes an `s` where the `a` used to be, goes to the beginning of the next line, and prints an `i`. The `z` is just never overridden because your program doesn't do it. I'm not sure what else to tell you. You could take an editor that has overriding mode and do this manually if you can't follow that algorithm in your head.
sbi